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:
"tradeIn" → "make" → "model" → "year" → "mileage"
Each question after "tradeIn" depends on the answer given to the previous question. Typical conditional visibility expressions (visibleIf) in this case look as follows:
{
"elements": [{
"name": "tradeIn",
"title": "Do you have a vehicle to trade in?"
}, {
"name": "make",
"title": "Vehicle make",
"visibleIf": "{tradeIn} = 'Yes'"
}, {
"name": "model",
"title": "Vehicle model",
"visibleIf": "{tradeIn} = 'Yes' and {make} notempty"
}, {
"name": "year",
"title": "Model year",
"visibleIf": "{tradeIn} = 'Yes' and {make} notempty and {model} notempty"
}, {
"name": "mileage",
"title": "Approximate mileage (miles)",
"visibleIf": "{tradeIn} = 'Yes' and {make} notempty and {model} notempty and {year} notempty"
}]
}
As you can see, cascade conditions accumulate, and the visibleIf expressions for the lowest-level questions ("year", "mileage", etc.) include conditions of the higher-level questions.
To shorten expressions, you can set the clearInvisibleValues property to "onHidden". With this setting, expressions may take into account only the previous-level question. For example, the "model" question can use visibleIf: "{make} notempty" instead of repeating the {tradeIn} = 'Yes' condition from the previous level.
Without clearInvisibleValues set to "onHidden", 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.
To see the abbreviated visibleIf expressions, view the survey JSON schema in the Code tab.
Note that this simplification also slightly changes the behavior. If a question had a value before hiding, this value will not reappear when the question becomes visible again. If this is not the desired behavior, we recommend using lengthy expressions.