I want to implement a repeat group question in CommCare, where I have a multiple-choice question with 5 options. I also have 5 sets of grouped questions, each of which should display based on the selected choice (using display conditions).
I have preconfigured the repeat group to open 5 instances.
The challenge I'm facing is how to configure the form so that once a choice (e.g., choice 1) is selected in the first repeat, it cannot be selected again in any of the remaining repeats. This restriction should apply to all the other choices as well.
Has anyone managed to configure something like this in CommCare?
Thanks for posting this. I think I can help you in this regard. To implement a repeat group in CommCare where each choice can only be selected once across multiple iterations, you can use a combination of hidden values and display conditions. Here’s a step-by-step approach:
Create a Hidden Value for Each Choice:
Create a hidden value for each choice that will keep track of whether the choice has been selected in any previous iteration.
Update Hidden Values:
Use calculations to update these hidden values based on the selections made in each repeat iteration. For example, if choice 1 is selected in the first iteration, set the hidden value for choice 1 to true.
Set Display Conditions:
For each multiple-choice question in the repeat group, set a display condition that checks the corresponding hidden value. If the hidden value for a choice is true, the choice should not be displayed.
Use XPath Expressions:
Use XPath expressions to dynamically update and check the hidden values. For example, you can use an expression like if(selected(/data/repeat_group[position() = current()/position() - 1]/choice, 'choice1'), true(), false()) to update the hidden value for choice 1. You can replace question ID's as per your app configuration.
Iterate and Test:
Test the form thoroughly to ensure that once a choice is selected in one iteration, it does not appear in subsequent iterations.
This approach ensures that each choice is only selectable once across all iterations of the repeat group. Let me know if you have any doubts in implementing these steps.