Select_multiple Label extraction to list

658
1
07-11-2022 01:25 PM
Labels (1)
Energy4all
New Contributor II

I have a select_multiple question that I want to use to populate another field so the labels, not names, of the selected choices are displayed.

I have tried using the jr:choice function but it only returns the first choice that is selected. What can I do so all selected labels are displayed in this new field?

Tags (2)
0 Kudos
1 Reply
LaurenceTait
Occasional Contributor II

I had similar challenge. You're right, the jr:choice function will only return the first choice. It can be worked around in a couple of ways.

You can copy your choices tab to a .csv file, and use the pulldata function to return the corresponding label.

Alternatively you can use javascript to test whether an answer has been selected and return the labels for the selected answers.

The CSV solution is probably better. You can directly call the CSV in the original question, which means that the choices and the labels will always align. It also has the advantage that it will reliably work offline. Javascript won't work if you're logged out, and once you go offline the field app routinely logs you out when the tablet goes to sleep.

The main problem with the CSV solution is that if you have a lot of choices, you end up with a huge calculation field in the XLSX sheet.

I've attached a copy of a worksheet that utilises both solutions. Hopefully one will be suitable for you.

 

Couple of notes

Because this site won't allow the upload of .js files, you'll need to copy the content of the .txt files into a js function called labelFunctions.

The js file has been riggedup to replace the comma separator between values with a space. You can modify it where it says join(" ")  by putting whatever joiner you like between the quotes.

Because I'm lazy, I've only made the sheet functional for the first 3 choices/labels. Following the same pattern, you can expend it out to as many choices as you like.

0 Kudos