Displaying selected options from multi-select as a separate list

I have the following multi-select question:
select_multiple delivery_complications

I want to create a list right below this which displays the options selected by user. Can someone share a snippet of how that’s done?

Here’s what I have tried:
I created a note data type and referenced the multi-select label with a choice-filter like this:

contains(${delivery_complications}, name) or name = 'none'

Here’s the complete variable:

note delivery_complications_risk ${delivery_complications} ${delivery_complications}

However, this gives me a space delimited list of names and not labels. How can I get an end line delimited list of labels?

Referencing a select_* variable gives the values and not the labels. You would have to use jr:choice-name(${variable}, 'value') for each of the values you’d want to retrieve the correct choice label.

E.g

if(selected(${delivery_complications}, 'xyz'), jr:choice-name(${delivery_complications}, 'xyz') would give the choice label associated with value ‘xyz’.

Here’s a link to the odk spec on jr:choice-name

1 Like

EDIT: this approach was initially tested with the Kobo form builder. Unfortunately no current cht-core release supports this pattern. This would however be supported when https://github.com/medic/cht-core/tree/6345-enketo-uplift merges.

The above pattern will not work with multiple selects.
The recommended approach would be slightly longer than what you would use with single selects.

For this multi selects, we would need to calculate each label separately using a combination of select-at and jr:choice-name and then concatenate them using join.

Let’s say we have the following under the choices sheet

list_name	name	label::en
gender	male	Male
gender	female	Female

and the following in the choices sheet

type	name	label::en	required	calculation
select_one gender	gender	Gender	true	
select_multiple gender	gender2	Gender 2	true	
calculate	calc_gender			jr:choice-name(${gender},'${gender}')
note	n_gender	Gender: ${calc_gender}		
calculate	calc_gender_1			jr:choice-name(selected-at(${gender2},0),'${gender2}')
calculate	calc_gender_2			jr:choice-name(selected-at(${gender2},1),'${gender2}')
calculate	selected_options			join(' ',${calc_gender_1}, ${calc_gender_2})
note	n_gender2	Gender: ${selected_options}				

You can see the last note dynamically updates with the appropriate labels from the multi select question.

cc @iesmail

1 Like

turns out, i believe, we were looking at the wrong problem - apologies for missing that detail.
the solutions above work for their specific usecases, but they all apply to forms. they render the label of the choice - on the form - which i believe is the default from what i’ve learned.

as also seen for the reasons - everything works as expected!

i should have asked about how to achieve the same for reports :man_facepalming:t5: as shown below for the stop message form.

the goal is to display labels in the reports, instead of the choice-name.

i hope that is clear enough. any pointers on how to achieve it will be much appreciated.

there is an ongoing discussion on the same