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?
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
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:
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!
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.
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:
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)
It works! it works! it works!
Thank you very much!
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
Dear Forum members,
I would like to ask for assistance for a similar issue.
We have the multiple choice question attached.
We would like to implement a validation logic whereas “none of the above” cannot be selected with any of the other answer options.
We tried with the following validation code but the code does not yet seem to work:
(not(selected(.,‘none_of_the_above’) and (selected(.,‘entrepreneurship_and_agricultural_econom’)))) or (not(selected(.,‘none_of_the_above’) and (selected(.,‘apo_and_cooperatives_fit_for_services_an’)))) or (not(selected(.,‘none_of_the_above’) and (selected(.,‘processing_entrepreneurship_and_economic’)))) or (not(selected(.,‘none_of_the_above’) and (selected(.,‘value_chain_promotion’)))) or (not(selected(.,‘none_of_the_above’) and (selected(.,‘inclusive_contract_farming’))))
Could anyone assist and help us check what is wrong with the code?
Maybe @Kal_Lam can assist?
Thank you so much for your help!
Simon
Sorry, I could resolve this issue now.
I have simply replaced “or” with “and”.
Thank you nonetheless! This thread has been helpful for me.
Best wishes
Simon
For anyone else looking for a similar solution, this post discussed previously should also be helpful: