Using read_only questions based on prev questions responses

Hello,

I have a question of ODK-Data Kit ( XLS forms ),

the issue of how assigning changeable value to read_only property to the question, based on prev responses,

for example i have a "are you single" (select_one yes_no) question
and the next question is ( how many children you have ), here i need to assign "True" to the second question if the first question response is "yes"

i tried the following

image

but it is not working !
Please if you have any ideas of suggestion help me,

The read_only property of a question/control in XForms can actually be an XPath expression, no different than a relevant or calculate expression (!). However, 99% of the time readonly is either always false or true, so the value is almost always a simple FALSE/no (which is actually shorthand for the XPath expression "false()"), or TRUE/yes (XPath "true()").

So if you want to make a question read-only or not depending on the response to a previous question, just write the same expression that you'd use for, say, making it relevant; eg

child: read_only = " ${marital}='yes' "

Here's a simple form you can try:

readonly.xls (18.5 KB)

[I've tested using an XPath expression for readonly under Collect and it appears to work as expected. But this does not seem to work under Enketo... @martijnr? ]

1 Like

Great, Thank you Xiphware for your clarifications,

Actually Yes, in terms of the Enketo, the code line did not work,
since my project on Enketo,

I tried to upload the sample on : http://opendatakit.org/xiframe/ ,no action response.

Hope @martijnr could provide us some suggestions.

Best

Sorry, this feature has not been implemented yet in Enketo. It's on the roadmap ("dynamic readonly") and I'm fairly confident, we'll get to it within the next 6 months: https://enketo.org/about/roadmap/

So I'm guessing Enketo allows full readonly XPath expressions, but that they're only going to be evaluated once at the beginning, when the form is first displayed, correct? (so if anything in that expression does change value over the course for the form, eg a selection, it wont actually affect anything)

I might suggest, @Hisham_Darwish, that in the interim till this feature is added to Enketo, that you resort to hiding the question instead of making it readonly, ie use relevant="..." instead of read_only="...". Relevant most certainly does work nicely under Enketo.

1 Like

Thank you Dears,

The roadmap looks great, your efforts are highly appreciated,

@Xiphware, thank you for the suggestion, but since "relevant" works by hiding question completely with its value, my plan was to keep the values of the {readonly} question instead, for easier analysis,

However will work with this current solution till publishing the new roadmap features.

Best regards.

@martijnr Dynamic readonly was on the Enketo roadmap back in 2019. It seems it is still not implemented. When will it be implemented?
Thank you!

1 Like

@Hisham_Darwish,
Design hints, please:
- Relevant even seems the better design option for your example. (Why show an empty question, in the case of single?)
- If you want to "keep the values of the {readonly} question, for easier analysis", you might use a calculate type. (What do you want to achieve here, please? Your readonly version would save an empty "" value.)
- Number of children should probably be type integer (Why decimal?)
- Also, unmarried/single women can have kids. (There are even a lot of single mothers < 18 years, worldwide.)