Conditional Validation Message

Hi,

Is it possible to do a conditional validation message? If I have two types
of validation messages against a question which should be displayed
depending on the type of answer, how do we display the same?

If this is not possible, can I refer a hidden_value to the "Validation
Message" column?

Thanks & Regards,
Jeffrey

Jeffrey,

Unfortunately an output ref referencing a hidden value won't work because
there's no way that I'm aware of to trigger the hidden value calculate
after the question is answered. I've found a solution here but it involves
custom XML. We usually advise againsnt this unless the feature is important
to you and you're very comfortable working with XForms by hand. You'll be
mostly on your own for debugging as we're not able to guarantee support for
custom XML behavior.

With that said, if you're comfortable with this you'll need to open the
source XML of your form under the Advanced tab of the form builder. Look
for the relevant question, then locate the jr:constraintMsg="" attribute of
this question. Here you'll enter the if() logic for the messages dependent
on the value of the question. For example my code was:

In this case I had a single select with three options with values of 1, 2,
and 3. This bind is enforcing that the answer has to be '1'. If the answer
is not one, the jr:constraintMsg checks if the question is '2' and if so,
shows 'two error message'; otherwise, the answer is '3' and it shows 'three
error message'. You could continue to embed if() statements for as many
conditions as you need.

Please note that this might cause strange behavior if you continue to make
changes in form builder; another risk of custom XML.

Good luck!
-Will

··· On Fri, Aug 22, 2014 at 2:53 AM, Jeffrey Jose wrote:

Hi,

Is it possible to do a conditional validation message? If I have two
types of validation messages against a question which should be displayed
depending on the type of answer, how do we display the same?

If this is not possible, can I refer a hidden_value to the "Validation
Message" column?

Thanks & Regards,
Jeffrey

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thanks Will. This is very helpful.

Warm Regards,
Jeffrey

··· On Fri, Aug 22, 2014 at 4:52 PM, William Pride wrote:

Jeffrey,

Unfortunately an output ref referencing a hidden value won't work because
there's no way that I'm aware of to trigger the hidden value calculate
after the question is answered. I've found a solution here but it involves
custom XML. We usually advise againsnt this unless the feature is important
to you and you're very comfortable working with XForms by hand. You'll be
mostly on your own for debugging as we're not able to guarantee support for
custom XML behavior.

With that said, if you're comfortable with this you'll need to open the
source XML of your form under the Advanced tab of the form builder. Look
for the relevant question, then locate the jr:constraintMsg="" attribute of
this question. Here you'll enter the if() logic for the messages dependent
on the value of the question. For example my code was:

In this case I had a single select with three options with values of 1, 2,
and 3. This bind is enforcing that the answer has to be '1'. If the answer
is not one, the jr:constraintMsg checks if the question is '2' and if so,
shows 'two error message'; otherwise, the answer is '3' and it shows 'three
error message'. You could continue to embed if() statements for as many
conditions as you need.

Please note that this might cause strange behavior if you continue to make
changes in form builder; another risk of custom XML.

Good luck!
-Will

On Fri, Aug 22, 2014 at 2:53 AM, Jeffrey Jose jeffreyjose@gmail.com wrote:

Hi,

Is it possible to do a conditional validation message? If I have two
types of validation messages against a question which should be displayed
depending on the type of answer, how do we display the same?

If this is not possible, can I refer a hidden_value to the "Validation
Message" column?

Thanks & Regards,
Jeffrey

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

We can achieve this using hidden values as well. Just make sure that if your app is multilingual you will have to create separate hidden values for each language otherwise the message will show up only in default language.