Visibility Requirements logic

I have a several Info by Template widgets that I want to show and hide based on the values in fields elsewhere in a form. There are a few that are a little more complex than the others and I’m having some trouble getting them to work as I’d like as I dont understand exactly how the AND vs OR logic is applying. It would be very helpful if I could add brackets to group statements together. Sorry for the wall of text.

Rough summary of the setup:
Data Dictionary Dropdown Field A (about 4 possible values)
Data Dictionary Dropdown Field B (about 4 possible values, some overlap with A but not all)
Data Dictionary radio button field C (3 possible values: Low, Medium, High)
Info by Template Widget 1
Info by Template Widget 2
There are other Data Dictionary Dropdowns and Info by Template widgets involved but they shouldn’t have any affect on this specific issue.

Desired setup
If A contains ‘Falls’ OR B contains ‘Falls’ AND C is not empty AND C not contains ‘High’ = display 1
If A contains ‘Falls’ OR B contains ‘Falls’ AND C contains ‘High’ = display 2
Otherwise display neither 1 nor 2

What I have entered in the visibility requirements for 1
OR
A contains ‘Falls’
OR
B contains ‘Falls’
AND
C is not empty
AND
C not contains ‘High’

What I have entered in the visibility requirements for 2
OR
A contains ‘Falls’
OR
B contains ‘Falls’
AND
C contains ‘High’

What happens:
A contains ‘Falls’, B is hidden, C is empty: 2 is shown (should be nothing)
A is hidden, B contains ‘Falls’, C is empty: 1 is shown (should be nothing)
A contains ‘Falls’, B is hidden, C is ‘Low’ or ‘Medium’: 1&2 are shown (should be just 1)
A contains ‘Falls’, B is hidden, C is ‘High’: 2 is shown (correct but I think it’s just always showing 2)
A is hidden, B contains ‘Falls’, C is ‘Low’ or ‘Medium’: 1 is shown (correct but I think it’s just always showing)
A is hidden, B contains ‘Falls’, C is ‘Low’ or ‘Medium’: 1&2 are shown (should just be 2)
A is hidden, B is hidden, C is anything: neither 1 nor 2 are shown (correct!)

Managed to solve this with a fragment callback to populate a hidden field with the value of the Data Dictionary dropdowns which allowed me to simplify the logic to only use ANDs. Would still be nice to know a bit more about how this logic works when you have a mix of AND and OR operators without being able to use brackets.

The ANDs will be evaluated before the ORs. So you can imagine brackets around any sets of AND criteria.

So your example:
A contains ‘Falls’
OR
B contains ‘Falls’
AND
C is not empty
AND
C not contains ‘High’

Is the same as:
A contains ‘Falls’
OR
(
B contains ‘Falls’
AND
C is not empty
AND
C not contains ‘High’
)

Depending on your requirements, having a mixture or AND and ORs may therefore give unexpected/undesired results. In these use cases it is usually advisable to use an alternative solution, such as you have found. Or possibly using subsets instead, which can have much more complex criteria nesting, but this does requires saving values first, such as in a multi-page form.

1 Like