How to set a constraint (validation) while selecting a response from a Multiple Choice Question

Within Multiple choice questions is there a way we can put a validation where, for the options of none-of-the -above, the other answers get erased or are not entered?

1 Like

Hello,
could you provide more details, maybe also form what you want to do. If it is just restricting that None can only be selected alone you will find previous community discussion, search for β€œcount-selected”…
Here a constraint example: None (label β€˜Z’) to be selected alone and the (others) total to maximal 5,
if( selected(., β€˜Z’), count-selected(.) = 1, count-selected(.) <= 5 ).
Kind regards

1 Like

Hi @anamikadutt,

Would you mind trying out as outlined in the image below to control your none of the above response in a multiple choice question:

In the survey tab of your xlsform:

In the choices tab of your xlsform:
Image 2

Data entry screen as seen in Enketo: When entered correctly

Data entry screen as seen in Enketo: When entry error is made

Reference xlsform:
Constraint.xlsx (12.6 KB)

Have a great day!

3 Likes

I have tried this but when I try to deploy my survey it always has this message error.

I have 4 choices; a, b, c and d

the condition is:
if a or b chosen, c and d cannot be chosen.

so I wrote the validation like this:
((not(selected(., β€˜a’)) and ((selected(.,’c’)) or (selected(.,’d’)))) or (not(selected(., β€˜b’)) and ((selected(.,’c’)) or (selected(.,’d’)))) or (not(selected(., β€˜c’)) and ((selected(.,’a’)) or (selected(.,’b’)))) or (not(selected(., β€˜d’)) and ((selected(.,’a’)) or (selected(.,’b’)))))

the code works, but not in the way that I want it.
The error message only shows when the 4 choices were selected at once.

Please help me to find where I went wrong.
Thanks.

1 Like

In this case, maybe you could do it as shown in the image shared below using this expressions in the constraint:

not(selected(., β€˜c’) and (selected(.,’a’) or selected(.,’b’))) and not(selected(., β€˜d’) and (selected(.,’a’) or selected(.,’b’)))

In the survey tab of your xlsform:

In the choices tab of your xlsform:

Image 2

Data entry screen as seen in Enekto: when data is entered as expected

Data entry screen as seen in Enekto: when data is not entered as expected

Data entry screen as seen in Enekto: when data is entered as expected

Data entry screen as seen in Enekto: when data is not entered as expected

Reference xlsform:

Constraint.xlsx (12.4 KB)

1 Like

It works! it works! it works!

Thank you very much! :slight_smile:

1 Like

This discussion thread is quite invaluable and has helped @DevAxle create a host of resultant variants. The validation_criterion function helps managers guide primary users and ease field application of data tools especially in LMICs.
Bravo all, and big thanks to @Kal_Lam

1 Like