Can I make relevant validations on the choices?

Regards, I would like as I can perform validations on response options that I have in the choices.
For example validate against the age of the person to be interviewed whether or not an answer option is displayed that I have hosted in the Choices? In the Survey this question is with a select_one

Thank you

I'm having a bit of trouble understanding your question. If English isn't your first language, please feel free to ask in your native tongue and we'll do our best? Or give a more concrete example of what exactly you'd like to have happen.

The generic response is that you want to use the selected(path, value) function documented here in the constraint for that field. An example from the ODK XForms Spec:

<bind nodeset="/d/s/my_select" type="select" constraint="selected(., 'c') and selected(., 'd'))" jr:constraintMsg="option c and d cannot be selected together" />

Hola Clint

Gracias por el consejo de escribir mejor en mi lengua nativa, se me
facilitara mucho mas el expresarme, realmente lo que necesito es realizar
una validación para que aparezca o no una determinada opción de respuesta
dependiendo la respuesta que se consigne en otra pregunta.

Yo tengo el programa en Excel para posteriormente convertirlo a Xlm y
subirlo al servidor.

Adjunto el ejemplo particular, en este le tengo las validaciones en el
Choices, pensando que funcionarias igual que cuando las coloco en el Survey
pero me doy cuenta que no.

Específicamente, si la persona respondió *menor a 18 *en la pregunta
"edad" (ubicada en el survey fila 8), cuando le pregunte "¿A cual
(pregunta ubicada en el survey fila 22) NO me debería mostrar la
opción *"Cotizante en el régimen contributivo" *opción de respuesta ubicada
en el choices fila 53.

Espero que si haya sido un poco mas detallada mi duda.

Saludos y muchas gracias

ejemplo_v3.xlsx (14.8 KB)

Ah! I understand better now. You're not looking for a validation, you're looking for something called a choice_filter.

The rules for choice_filter work the same as constraint and relevant, but instead of being checked against only the inputted data, they can also look at the choice data you give on the choices worksheet. The rule is evaluated against both the form data and the choice data, and only choices that pass the rule will be presented. References like ${this} look at form data, and names like this look at choice data.

In your example, you could add a rule in cell I22 of the survey sheet like this:

name != '1' or ${edad} < 18

This way, all the choices with a name (the value in column B on the choices worksheet) that isn't '1' will always show, and even if the name is '1', it will show as long as the age is at least 18.


I see how you tried to do it, by adding a relevant column to the choices worksheet. This doesn't work, because choices don't understand relevant. But I actually kind of like how you tried to do it, it makes a lot of sense. I wonder if @yanokwa agrees and whether this kind of approach could be allowed as well.

Estimado Clint

Es usted muy amable por la respuesta, voy a implementarla para mirar los
resultados, es muy gratificante poder contar con una comunidad tan unida y
preocupada por ayudar a todos.

Muchas gracias

1 Like

:slight_smile: Good luck! Let us know how it goes.