Los triggers 1.1, 1.6, 1.13 muestran solo Sí · No (sin "Prefiero no decir")

Al responder "No" en las tres, el formulario salta a 6.4 (no muestra secciones 2-5 ni 6.1-6.3)
La pregunta 6.6 aparece antes del cierre
Las preguntas multiple_choice muestran el hint "Podés marcar más de una opción"
This commit is contained in:
markosbenitez
2026-06-10 15:49:05 -03:00
parent bf963e8894
commit 157e108322
15 changed files with 1096 additions and 161 deletions

View File

@@ -11,9 +11,17 @@ export function isQuestionVisible(
return rules.every((rule) => evaluateRule(rule, answers))
}
/** Normalizes if_question to an array of codes regardless of rule shape. */
export function ruleQuestionCodes(rule: ConditionalRule): string[] {
return Array.isArray(rule.if_question) ? rule.if_question : [rule.if_question]
}
function evaluateRule(rule: ConditionalRule, answers: FormAnswers): boolean {
if (rule.op === 'eq') {
return answers[rule.if_question] === rule.value
return answers[rule.if_question as string] === rule.value
}
if (rule.op === 'eq_any') {
return ruleQuestionCodes(rule).some((code) => answers[code] === rule.value)
}
return false
}
@@ -32,8 +40,8 @@ export function getHiddenCodes(
return questions
.filter((q) => {
if (!q.conditional_rules?.length) return false
const dependsOnTrigger = q.conditional_rules.some(
(r) => r.if_question === triggerCode
const dependsOnTrigger = q.conditional_rules.some((r) =>
ruleQuestionCodes(r).includes(triggerCode)
)
if (!dependsOnTrigger) return false
return !isQuestionVisible(q, projected)
@@ -46,7 +54,7 @@ export function getTriggerCodes(questions: Question[]): Set<string> {
const triggers = new Set<string>()
for (const q of questions) {
for (const rule of q.conditional_rules ?? []) {
triggers.add(rule.if_question)
for (const code of ruleQuestionCodes(rule)) triggers.add(code)
}
}
return triggers

View File

@@ -19,8 +19,8 @@ export interface RatingOptions {
}
export interface ConditionalRule {
if_question: string
op: 'eq'
if_question: string | string[]
op: 'eq' | 'eq_any'
value: string
action: 'show'
}