XLS form- Repeat select_one question until "A" is selected

To achieve something like this, you can define the repeat count in terms of your desired condition.

This indefinite-repeat XLSForm shows an example of that technique. The key part is that the count is set to

if (${count} = 0 
    or (${person}[position()=${count}]/choice != '' and ${person}[position()=${count}]/choice != 'a'), 
    ${count} + 1, 
    ${count})

edited 6/2020 to use ${} for repeat reference instead of XPath path

This says that if there are currently no repeats or your ending condition (user has selected "a") is not met, we should add one to the desired repeat count. If there are repeats already and the user has selected "a", we should keep the desired repeat count the same which means no new repeats are created. This is similar to the relevant idea @Xiphware was suggesting but it is fully dynamic. You could have any other test in there like age being greater than 50, "a" being selected AND age being greater than 50, etc.

${person}[position()=${count}]/choice uses XPath notation to identify the choice selected in the last iteration. You could also do this with indexed-repeat if you're more comfortable with it (I can never remember how it works!). The idea is that ${count} represents the number of repeats added so far and is also the index of the latest iteration.

If you think a user could go back and modify one of their answers, you'll want to use the technique described at https://github.com/opendatakit/docs/issues/726 so that if a user selects A in a previous repeat, the ones after it aren't shown.

I've also used the technique @Joseph_E_Flack_IV describes and although it may require a bit more thinking on the enumerators' part, it tends to work well.

Hopefully this addresses the use case generally enough that no specification additions are needed!

6 Likes