I’ve been stuck for two days on configuring default options for a select_multiple question.
I am working on a form designed to both register new entities and update existing ones. Everything is functioning correctly so far; if the entity already exists, the form triggers an update.
The issue I'm facing is that I want the previously recorded data to be pre-selected in the multiple-choice list during an update. While I know how to set default values using hardcoded strings, in this specific case, the defaults are stored in variables: ${savedClasse} or ${savedOption}.
I have searched extensively and read that dynamic defaults for select_multiple might not be directly supported. Does anyone know of a workaround or a specific technique to bypass this constraint?
I’ve attached my form for reference. Thank you in advance for your help!
I'm also interested in the solution to this. Just taking a quick look, when you put a note in line 7 just after the 3 calculate fields to help debug, if you put
${savedClasse}
${savedOption}
in the label column, does it correctly display/fetch these variables from the entity list? For this kind of thing I always end up having to make a note to be 100% confident that what I think is coming in as a default is actually accurate.
Have you tried putting the calculated default (eg ${savedClasse}) into the calculate column, not the default column? And don't forget to add a trigger, as otherwise any user changes will be wiped out when it recalculates.
Edit: here's an example, it's an internal lookup, but shows the question loading the default once triggered. Select_multiple-dynamic.xlsx (95.9 KB)
Thank you for asking this, as it caused me to reevaluate my understanding of how once works - previously I thought it executed when the form loaded or a repeat is created and that was it, so it wouldn't be much use.
Now as I understand it, if the target question is blank and the result of the once calculation is not blank, it will evaluate and populate the field.
Possible downsides of this are answering the target question before the question that feeds the once expression is answered or changing the response to the question that feeds the expression for the target. In both cases once won't do anything as the target field is not blank.
Depending on form workflow once(expression) may be preferred to expression plus a ${trigger-field}
I wanted to follow up and share. my form is now working perfectly after following your advice.
I was attempting to use the ${savedClasse} in the default column, which wasn't behaving as expected.
I moved the calculation from the default column to the calculate column, added a trigger (as in your file). the form now correctly pulls the ${saved_value} and my multiple-choice list is now loading stored values. This was the missing piece of the puzzle.