Simplify Cascade Conditions
In a cascade condition, a question's visibility depends on the previous question, whose visibility, in turn, depends on a question before it, and so on. Cascade conditions may result in lengthy Boolean expressions because each expression must include conditions from previous cascade levels. In this example, questions form the following multi-level cascade:
"age18"
→ "haveKids"
→ "kidCount"
→ "kid1Age"
, "kid2Age"
,"kid3Age"
, ...
Each question beginning with "haveKids"
depends on the answer given to the previous question. Typical visibleIf
expressions in this case look as follows:
{
"elements": [{
"name": "age18",
"title": "Are you 18 years old or older?"
}, {
"name": "haveKids",
"title": "Do you have children?",
"visibleIf": "{age18} = 'Yes'"
}, {
"name": "kidCount",
"title": "How many children do you have?",
"visibleIf": "{age18} = 'Yes' and {haveKids} = 'Yes'"
}, {
"name": "kid1Age",
"title": "How old is your first child?",
"visibleIf": "{age18} = 'Yes' and {haveKids} = 'Yes' and {kidCount} >= 1"
}, {
"name": "kid2Age",
"title": "How old is your second child?",
"visibleIf": "{age18} = 'Yes' and {haveKids} = 'Yes' and {kidCount} >= 2"
}, {
"name": "kid3Age",
"title": "How old is your third child?",
"visibleIf": "{age18} = 'Yes' and {haveKids} = 'Yes' and {kidCount} >= 3"
}, {
"name": "kid4Age",
"title": "How old is your fourth child?",
"visibleIf": "{age18} = 'Yes' and {haveKids} = 'Yes' and {kidCount} >= 4"
}, {
"name": "kid5Age",
"title": "How old is your fifth child?",
"visibleIf": "{age18} = 'Yes' and {haveKids} = 'Yes' and {kidCount} >= 5"
}]
}
As you can see, cascade conditions accumulate, and the visibleIf
expressions for the lowest-level questions ("kid1Age"
, "kid2Age"
, etc.) include conditions of the higher-level questions.
To shorten expressions, you can set the clearInvisibleValues
property to "onHidden"
. With this setting, expressions can take into account only the previous-level question, as shown in this example. Without clearInvisibleValues
set to "onHidden"
, such behavior is impossible because hidden questions retain their values. If you used shorter expressions in this case, a change in a higher-level question wouldn't propagate down the cascade, and lowest-level questions would remain visible even though questions upon which they depend were hidden.
Note that this simplification also slightly changes the behavior. If a question had a value before hiding, this value will not reappear after the question becomes visible again. If this is not the desired behavior, we recommend using lengthy expressions.