Select_one from repeat - different value and label

1. What is the general goal of the feature?
To use the select_one ${from_repeat} feature, but being able to specify two different questions within the same repeat as value/name and label. Currently the ${from_repeat} repeat question is used as both name and label.

2. What are some example use cases for this feature?
Household questionnaire:

  • Repeat group (household roster)
    • member_name
    • Auto-generated unique ID
  • Select_one ${member_name} - choose the main beneficiary / head of household

This set-up is useful to be able to apply a choice filter on the household members that can e.g. be selected as main beneficiary. The member names are displayed as labels which is great, but the value stored is also a member name. With an option to specify different labels and names, this select_one could instead save that member's unique ID.

This would save having to transform the data after collection. It also helps avoid errors due to different people having the same name (e.g. across households), or different project sites having similar names (across different administrative regions), etc. and seems generally better practice.

An added benefit might be allowing select_multiple from repeat, as a form could have:

  • Repeat group
    • Text input for "Full Name" with spaces
    • Calculate field transforming to "full_name" with underscores

This would mean the output of the select_multiple (space separated array) would not have errors from spaces in the names.

3. What can you contribute to making this feature a reality?

Possible suggestion on how to show in XLSform: I don't know if the parameters tab could allow for value=../name_field or label=../label_field or even alternatively label='label_field' with a constraint that it had to be a node at the same level as the initial select_one ${repeat_question}?

I haven't yet contributed to pyxform but would be happy to have a go to get started if helpful. I confirmed at this line of that the same node was being used for value and label

Hi @amschel, thanks for making this suggestion and offering to take it on! I agree that it would be valuable.

We use parameters as a real grab-bag. It feels like the right place for this new functionality to me. You'll see that parameters are detected, validated, and sent to the right place in a big conditional based on question type. It's not an ideal structure (

I have a preference for this option because it feels a bit more consistent with what's supported right now. The default would be to use the specified reference for both label and value and what you add would make it possible to override just the label.

I would prefer label=${label_field}. I think that's easier for a user who doesn't know about XPath to reason about because it's more consistent with the way they are used to writing references.

For validation, I think your pyxform implementation would be able to convert the ${} notation to XPath for both the field specified for the select (which would represent the value) and the label parameter in the context of the question node. Then your code could verify that the two paths (excluding the terminal nodes) match. That's the simplest option I can think of. It would mean both have to be in the same group, though, which is not strictly required. There may be a more accurate way to validate that the two are in the same repeat ignoring groups but I'm not thinking of it off the top of my head.

Consider opening up a draft PR as you get started if you have any questions!

1 Like