Pre-select yes/no question

I have a yes/no question and would like to pre-select it with value “Yes” based on some condition. I am aware that I can use the default column to pre-populate the value but that’s not what I want to do. I want to select “Yes” value based on a condition.

Here’s the condition: if(${previous_med}!= '',${received_med} = yes,${received_med} = no)

${received_med} is the Yes/No question.

I have tried to add this condition in the calculate column but that did not help. Any other ideas?

1 Like

I believe calculate can be used to set a default value, but if you do so - the value cannot be changed throught he UI. It is “stuck” on the value you calculate as default because the calculated value is re-assigned infinitely. With the upgrade to Enketo core scheduled in 3.12, we should get access to more of the standard ODK functions including the use of once. That will allow you to do set a calculate value of once(if(${previous_med}!= '',${received_med} = yes,${received_med} = no)) which should hopefully solve this.

Until that is released, I’ve seen this workaround used:

  1. Create a calculate field called myDefault with desired default value. So in your case: if(${previous_med}!= '',${received_med} = yes,${received_med} = no)
  2. Create the select_one field called myValue with calculate if(${once}=’’,${myDefault},${myValue})
  3. Create a calculate field called once with a calculated value of true. This field needs to appear after the text field.

This solution relies on the order of execution of the Enketo library - so ${once} is empty the first time that myValue is calculated and then it is true in subsequent calculations. Hopefully this can give you the behavior you need until the enketo bump comes in 3.12. Sorry it is hacky and gross.

1 Like

HI @kenn ,

I upgraded to 3.12 locally and I used once but it does not pre-select the response. In my case, I was expecting it to pre-select the yes option.

I added the following under the “Default” column for the yes/no question:

once(if(${previous_bopv0}!= 0,${received_bopv0} = “yes”,${received_bopv0} = “no”))

I have confirmed that previous_bopv0 does not return 0.

Unfortunately, I don’t think the Enketo core upgrade made it into 3.12 (I said it would be above). @jkuester is working on it presently, I believe and he can help to reset expectations.

Yes, unfortunately @kenn is correct. The Enketo core upgrade did not make it into 3.12, but I am actively working on it and we hope to get it released soon (though at this point it is probably not going to make it into 3.13 either).

I will add this case to our list of things to test as part of the uplift.