Require one answer within a nested repeat group

684
5
04-09-2020 08:33 AM
Soper_Chuck
New Contributor III

I recently asked this question and Doug Browning answered pretty quickly. Thanks for that.

Require one answer within group 

I actually need to use this repeat group within another repeat group. I've attached a modified XLSForm to show that usage. My survey requires this case. When I add another person, the continent question is required (that's good) but, the city (1 required, up to 5) is not required. When I have one person and submit the survey, the city is required, but the constraint message is in an alert and the content is not auto-scrolled to the correct location. Worse, if I have two people and will a total of one city (one city per person should be required) then the survey is accepted.

Does anyone know how to require one city per person? Also, I prefer that the constraint is inline and not in an alert. And that the city is required when adding a new person (like the continent question). 

0 Kudos
5 Replies
DougBrowning
MVP Esteemed Contributor

That is tough due to the dependency cycle.  Seems like a constraint of ${city_count}>=1 on the city_count_desc field seems to work.

0 Kudos
Soper_Chuck
New Contributor III

Thanks. I moved the constraint of ${city_count}>=1 to the city_count_desc field. That's an improvement. It kind of works, but not completely.

Success:

  • With one person, continent answer exists, and no city. During submission constraint message (saying at least one city is required) is displayed in an alert. Note: it won't auto-scroll to the city field (if the city field isn't visible).
  • With one person (continent answer exists and city selected), I add a second person and only answer the continent question. During submission constraint message (saying at least one city is required) is displayed in an alert. 

Failure:

  • When I add a second person, the continent answer is required (for the first person), but at least one city is not required (for the first person).
  • With one person (continent answer exists and city selected), I add a second person and only answer the continent question. Then, I scroll back to view the first person. Submission is successful, but the second person doesn't have a city.

Does anyone see a solution for these cases?

0 Kudos
DougBrowning
MVP Esteemed Contributor

Yes it gets confused with the repeat in a repeat.  It is counting all responses which makes sense.

Can you just have 5 city fields instead?  The backend table will be less pretty of course

You could also remove the repeat count of 5.  Then make City required.  They could then do more than 5 but not less than 1.  You could give a warning past 5 though.  Or even hide the fields of the count > 5 and have a message appear that says max of 5.

None are perfect but its a shot.

Soper_Chuck
New Contributor III

Yes! I believe that having five city fields would solve the issues I discovered. I could display each additional city field as they're entered. That is, after the first city is entered, display the question for the second city, and so on.

My question about entering 1 to 5 cities within a repeating group is relatively straightforward. In my actual survey, I have a select_multiple

    with 13 choices. Four of the thirteen choices, if checked require the at least 1 and up to 5 "cities" question. Those city questions have to be displayed below the 13 choice list question. Each city question takes a lot of screen space. I could consider asking the user how many "cities" they need to enter so that I can immediately display correct number of city questions. The entire approach (of asking for 1 to 5 cities) would have to be done four times, for each of the 4 (out of 13) choices selected.

This isn't a good user experience. I would also like a way to quickly review all answers before submitting the survey and that isn't easy (if it's possible).

0 Kudos
DougBrowning
MVP Esteemed Contributor

I made an edit with 2 more ideas.

0 Kudos