Select_one in repeated group - define/restrict number of times an option can be selected

1. What is the problem? Be very detailed.
In the attached form, i want the enumerator to specify the relationship of each individual with the head of household i have the below options:

  1. Self
  2. Spouse
  3. Son/Daughter
  4. Sibling
  5. Grandparent
  6. Grandchild
  7. Son/daughter in law
  8. Mother/Mother in law
  9. Father/Father in law
  10. Other relative
  11. Non-relative

I need to restrict and make it mandatory to select one individual as head of household (option 1)
Allow (option 5/grandparent) to be selected 4 times maximum 0 is allowed.
Allow options 8 and 9 to be selected 2 times maximum 0 is allowed.

2. What app or server are you using and on what device and operating system? Include version numbers.
Using ONA as a server and ODK collect v2021.2.4 for data collection

3. What you have you tried to fix the problem?
NA

4. What steps can we take to reproduce the problem?
I don't know

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.
relationship to head of household.xlsx (12.4 KB)

Hello @CS,

There are plenty ways for you to implement the desired restrictions. I added few rows in your form (self-explanatory). For some reasons, Enketo doesn't render well the choice_filters, consider testing the form in ODK for optimal results

Summary of work-around:

  • Use choice_filter() to limit available options based on repeat index
  • create counters of relationship occurrences (Grandpa, Mothers and Fathers) inside repeat
  • Outside repeat, sum() the occurrences
  • Inside the repeat, set constraint() or warning messages as note label or hint based on set thresholds and inform user on what to do via same note or constraint_message()

Hoping this helps, and Happy new year.

Jules R

relationship to head of household.xlsx (13.5 KB)

Took about 11 members (3 Mothers, 3 Fathers, 5 GrandParents) to get all errors messages in a picture below

Hello @jules_rugwiro,
The shared code helped me get to the result needed. I just did a little twist as i needed the applicant data to be filled first regardless if this is the head of household or not.
I used the same logic used for the other household members.
Thanks for the support and happy new year:)
Chris