Dynamic default overlaps user answer in select_one question

1. What is the problem? Be very detailed.
I am trying to develop a conditional choice filter for a select_one question in my form. This select_one question is located inside a repeat_group, and the choice_filter works in order to hide the options that were already selected in the previous repeat instances. Also, I need to develop a dynamic default for this select_one question, and the default is only generated when a previous select_one question is answered with "No". On the other hand, when the user select "Yes" in this question, the next select_one needs to work normally, and the user can select any option.

However, when the user choose 'Yes', the next select_one keeps empty, even if the user select an option.

2. What app or server are you using and on what device and operating system? Include version numbers.

I use the ODK Collect v.1.27.2 and KoboToolBox server

3. What you have you tried to fix the problem?
I tried to change the dynamic default conditional, because I think that the problem may be in the "else" argument, where I put '' . However, I don't know how I could possibly change it to work properly.

4. What steps can we take to reproduce the problem?

Please, take a look in the xlsform I attached. dynamic-default.xlsx (12.4 KB)

The conditional I mentioned is located in the calculation column for the variable section_default

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.

Already attached.

Hi @ricardonfc
welcome to the forum! Please introduce yourself here!

It's the way it works it happens because calculation is always evaluated and always returns a value even if it's null or empty string...

@LN isn't it possible to evaluate calculation only under some circumstances like in this case? If it isn't possible maybe we should consider it?

Hello @Grzesiek2010, thank you for the attention!

Yes, I noticed this aspect in the calculation. For a moment, I thought if it would be possible to exclude the empty string argument, so the conditional would only work with the if part, but nothing would occur with the else part, so the default would not appear if I selected 'Yes'. But I don't know if it would really work. Actually, conditional sentences accepts at least 3 arguments, so for now it would not be possible to try this.

However, I tried one thing that worked in certain way. I put the dynamic default inside an once() function, so the calculate variable will not be calculated everytime. It's a good approach for now I think, but if the user needs to come back to the page and re-select the 'Yes' or 'No' question, the default will not be calculated again.

I think that this approach will handle the situation in many cases, but if there is any other possibility of using the calculation under circunstances like this, it would be really cool!

As of pyxform v1.2.0 and XLSForm Online v2.2.0, there's a native way to do this kind of dynamic default.

You can use the XLSForm trigger column to define when a given field's calculation should be evaluated. You can read more in the XLSForm docs for trigger and the ODK docs on dynamic defaults.

I believe that in the original form shared, the only necessary change would be to add a trigger column and to put ${sampling} in that column for the section_default row. This would indicate that when the sampling selection changes, the default for sampling_section should be recomputed. The user is then free to override that default if appropriate and sampling_section's value will be retained unless sampling changes again.

3 Likes

@LN: I fell for it (that will teach me to read the documentation more carefully as I had completely missed this)

What may be tricky if you forget to trigger the evaluation of your calculation is that you can have interference with same XLSForms being used in distinct ODK Central projects when the same tablet is (re-)used :upside_down_face:

Very minor impact in my case, as only an issue with an old label (associated to a select question) that was used during the pilot phase of the project ("pilot" project on ODK Central) suddenly reappearing in July's submissions instead of the new label as defined in the new form (distinct "main" project on ODK Central) after this went completely undetected when data were collected in April-May as using a different device, so better to not miss this part of the documentation!