Checkbox conditions

Hi all
I used a checkbox question to answer the type of a disease treatment. The options are: Pills, Diet, Excecice, None, Other. A patient could take more of one at a time, but if the patient select none and diet, for example, can move to the next question; this doesn´t make sense. I want to place a kind of condition: if the patient select the option none, then to block other options.

Or I may place a question before: Are you taking any treatment? Yes or No. If yes then pop up the treatment options.

What do you think is the best option? Do you have other solution to this issue?

Thanks in advance!

Hi Marcos,

You can use a validation condition to prevent the user from selecting 'none' in concert with additional options.

I think something like

. = 'none' or not(selected( . , 'none'))

Which would mean "either the question is exclusively answered with 'none' or 'none' is not one of the selected options"

-Clayton

1 Like

Hi Clayton,

I have a similar question. I want to add the validation condition, to a question with a condition already. I how can I effectively put the two together, I've tried using 'and' as well as attempting to put the validation statement into the conditional statement to no effect.

This is what I need the validation condition to run on .
cond(question7 = 'no_debt', 0, (5 - count-selected(question 7)))

I

Hi,

Seems like your conditional statement return a number. If you write any logic with numbers as argument, the result can be surprising... The result of any calculation before and after the logic function (OR, AND, etc.) should be either TRUE or FALSE.

Can you describe the next validation condition you want to add ?

-Michel

Yes, I want to add the checkbox validation to this statement: cond(question7 = ‘no_debt’, 0, (5 - count-selected(question 7)))

I basically have a question that I need to be assigned on of the answer choices to be assigned ,0, like "no debt will have an answer choice value of 0) and everything else should be included in this conditional (5-counted-selected) but I also need a statement that doesn't allow them to selected , 0 and another option

Then you can try something like that :

the response is valide if :
.= if(question7='no_debt', 0, '') and (not(selected( . , ‘none’) and count-selected(.)>1))

-Michel

Hi Michel, but where would the (5-count-selected() go?, I need the overall number of items selected to be subtracted by 5. Should I wrap the whole statement in a cond()?

I don't know why you would need the overall number of items subtracted by 5 since you were looking for a validation condition :

Maybe I'm missing something here...

-Michel

I will try to clarify,

I have scoring associated with question, and at the end of the form all questions with be averaged.. I have 6 responses numbered 0-5 ( with response 0, no debt.). I then have to take the value (count selected) and subtract it from 5.( the scoring was derived by another team) This is what I have:

The problem is I can't figure out where the to add the validation condition to my original calculation

Note: I assigned the value of 5 to 'no debt' so that when ran through the cond(count-selected) it would return 0. However, without the validation condition, users can still select '0' ie. no debt, and the other options .

Thanks for the advice/suggestions

Hi Shawn,

Validation conditions are used to prevent the user from providing erroneous input on individual questions, so you may find it difficult to "reverse" the logic up if you are factoring in multiple questions as part of what needs to be validated.

Another approach that you may gain more value from would be to add a Label question to your form which is only displayed when the inputs provided from the user are Invalid, and which has a validation condition of false(), which acts as an error message for the user for their inputs across multiple questions.

That drastically simplifies the logic you'll need to introduce, while providing the user with a single place to see the error that their inputs were invalid.

-Clayton

Hi Clayton, I was able to configure it to let me run the application in the webb apps however, I was not able to select an answer choice whether it was 0, or 1, 2, 3 for either of my 2 questions requiring this validation condition of See:


and

What could I be doing wrong? Thanks again Clayton, or Michel, or whomever responds

I'm sorry I couldn't understand your request sooner. Here is what I have in commcareHQ :


and

nothing to be added than
not(selected( . , ‘0’) and count-selected(.)>1) in the validation condition.

-Michel

Thanks Michel, I realized I uploaded the wrong pictures, but I resolved the issue. Also, you have been super helpful. I appreciate your expertise.

Thank you, Michel and SFitz, if i want to select more than one, above multi choice options with "unsure", how to write a validation condition?