Checkbox validation based on previous checkbox response


(Eric Jospe) #1

Hello,

I have two checkbox questions with the same list of 14 responses. I would like to add a validation condition to the second question that prevents mobile users from selecting any option that was NOT selected in the first question. Is this possible, and how might I structure it? My only thought so far is to use count-select to make sure the number of options selected in the second is equal to or less than the number selected in the first question, but that’s not quite what I want.

Thanks!


(Michel Akkaoui - de Sousa) #2

Hi,

You should have a look a the examples here :
https://confluence.dimagi.com/display/commcarepublic/Logic+for+Checkbox+Questions

I believe your expression for the validation condition would look like
if(
not(selected(/previous_question,‘option1’)),
not(selected(.,‘option1’)),
false()
)
and
if(
not(selected(/previous_question,‘option2’)),
not(selected(.,‘option2’)),
false()
)
and

and
if(
not(selected(/previous_question,‘option14’)),
not(selected(.,‘option14’)),
false()
)

Basically testing that all choices not selected in the first question remain not selected in the second question.
I can be wrong though… should be tested…

-Michel