Limit Number of Select_One Options

Hi all,
I am currently building an XLSForm. Attached is a subset of the current form.
In our survey, we have three main parts. For each household that we survey, we want a different member to answer each of the three parts. For example, Member 1 answers the first part, Member 2 answers the second part, and Member 3 answers the third part.

We enter the names of the household members inside a repeat group. Then, we pull all of the names that are entered into the repeat group using a calculate question type with an indexed-repeat function.

At the beginning of each different part of the survey, we want the enumerator to select who, among the household members, will be taking that part of the survey. We would like it to be a select_one question type to reduce potential enumerator error with entering the name of the respondent again.

Since each household will have different amounts of members, I have set up the form to pull 30 names that are entered. This also means that for the select_one question at the end of the form, there will be 30 options to choose. If the enumerator only inputs 5 names, then 5 names will show up on the select_one question, with 25 blank options. The enumerator will still be able to select a blank option, which is bad.

I want to limit the number of options available for the select_one question, based on how many household members' names are inputted, but still allow for a (virtually) unlimited amount of names to be inputted. For example, in House 1, there are 7 members, so only 7 options will show up on the select_one question. But, in House 2, there are 13 options. The enumerator will still be able to enter in 13 names, and have 13 options show for the select_one question.

I hope this makes sense. Thanks in advance for your help.test_people.xlsx (18.9 KB)

To do this truly dynamically I believe you will need to edit the raw XML of your form. Luckily it's a pretty small modification! Take a look at Generate multiple choice alternatives, based on the answers in a repeat - #4 by LN for the general process.

Thanks for the help, Hélène.

I am (very) new to editing XML code. I was able to get the code to work on a much smaller form. On my larger form, though, I'm having some troubles. The Aggregate server pops up with this error: Problem with JavaRosa Parsing Form: org.opendatakit.aggregate.exception.ODKIncompleteSubmissionData: Javarosa failed to construct a FormDef. Is this an XForm definition?

Here's my original XML:
>

        <label ref="jr:itext('/ThreeIE_Phase2ODK_21NOV17_sqs/present/latrine_yes/group_consent/person_f:label')"/>
        <item>
          <label ref="jr:itext('/ThreeIE_Phase2ODK_21NOV17_sqs/present/latrine_yes/group_consent/person_f/1:label')"/>
          <value>1</value>
        </item>
        <item>
          <label ref="jr:itext('/ThreeIE_Phase2ODK_21NOV17_sqs/present/latrine_yes/group_consent/person_f/2:label')"/>
          <value>2</value>
        </item>
      </select1>

And here's my edited version:
>

        <label ref="jr:itext('/ThreeIE_Phase2ODK_21NOV17_sqs/present/latrine_yes/group_consent/person_f:label')"/>
  		<itemset nodeset="/ThreeIE_Phase2ODK_21NOV17_sqs/present/latrine_yes/group_consent/hh_member/hh_demo">
  			<value ref="name_mem"/>
  			<label ref="name_mem"/>
  		</itemset>
      </select1>

Any ideas as to what the problem is? Thanks a lot!

P.S. This is just the part that I edited. When I download it directly from the ODK validator, and then upload it to the aggregate server, the survey uploads perfectly fine.

I'm not totally clear on when you're getting that error, it sounds like it's not on form upload but when submitting from Collect?

If your form can be shared publicly, it would really help to have the whole thing!

I found the solution for my problem, thanks to Hélène:

In my form, the "hh_demo" is a group name, that has the "name_mem" question nested in it. "name_mem" is the question where the enumerator inputs the name of the member of the household.

When editing the XML, I moved the "hh_demo" down to the "value" and "label" properties, instead of including it into the "itemset" property. So, the proper XML that works for my problem is:

	<itemset nodeset="/ThreeIE_Phase2ODK_21NOV17_sqs/present/latrine_yes/group_consent/hh_member">
		<value ref="hh_demo/name_mem"/>
		<label ref="hh_demo/name_mem"/>
	</itemset>

Note: You do not need to touch the "select1" and "label" lines in the original code.

1 Like