A very common question our support team receives goes something like this:
“We've noticed a problem in the survey we’re working on. We have a repeat group with a repeat_count based on a previous question. If we enter a number like 4, for example, and then go into the repeat group, we can go through the repeat group 3 times, as we would expect. If we go back and change the number to 5, this adds another group onto the repeat group, again, as expected. But if we go back and change the number to 3, we still have 4 repeat groups to fill out. Why does it change when we revise the number up but not down? Is there a way to get rid of this extra repeat? Our surveyors don’t know what to do.”
Non-destructive design
Don’t worry, nothing is amiss here. This is actually functioning as intended, and I'll explain why. One of SurveyCTO's core design principles is that it is non-destructive with data. To continue with our earlier example, let’s say we are listing names of household members. First, we ask, “How many people are members of your household?” and the respondent answers “4.” So we enter 4, and then the repeat group asks us to enter the names of the four people.
- Person 1
- Person 2
- Person 3
- Person 4
After we’ve entered their names, the respondent decides that actually, there are only 3 members of their household. So we go back to the question “How many people live in your household?” and change that number to ‘3’. Now, there should be 3 repeats in the repeat group, right?
However, you’ve put the SurveyCTO Collect app in a rather awkward position. How should it decide which household member (and thus, repeat instance) to remove? If you’re having trouble answering that question, good, because it’s not a question that can be answered without more information. And because the answer is “it depends,” SurveyCTO will not remove a repeat group on its own because that would violate our core design principle that it is non-destructive with data.
What can you do in your form designs to prevent unwanted repeats?
The best measure you can take is to apply a clever relevance expression to your repeat group, so the repeat group "shrinks" when the repeat_count goes down. This involves making the whole repeat group relevant only if the index() value is less than or equal to the source of a dynamic repeat count that might change. For example, if the repeat_count of the repeat group is simply ${rep_count}
, you can give the repeat group this relevance expression:
index() <= ${rep_count}
Copy and adapt this method exactly from this sample form design (see the relevance for the repeat group named "repeat_group"). To try the sample form before you use the method in your own form, check out our support article on deploying form definitions.
You can also use the "table" appearance for repeat groups to help you keep track of the number of repeats.
When a large number of repeat instances will be needed (such as for larger households), it can be challenging to define the repeat_count in an integer field, since you may not know how many repeat instances you need until you get started. Instead, you can leave the repeat_count blank, so repeat instances are manually added. Manually added repeat instances can also help you keep better track, as opposed to methods where you take the repeat_count from an integer field (for example).
What can form users do with unwanted repeats?
Enumerators can also remove the repeat instances while filling out the form.
If you do not use the relevance method mentioned above, SurveyCTO Collect has no way of knowing which repeat group instance you want to get rid of on its own. You have to tell it which instance of a repeat group you want to remove after you’ve revised the count down or changed the selected options in a select_multiple field. To do this in SurveyCTO Collect, "long-press" (hold your finger down for a second until the device vibrates) in a field inside the unwanted repeat instance. A menu will appear, allowing you to remove that response, or remove the group as a whole. This is our recommended approach to revising repeat_counts down.
Please note that you should revise the repeat_count down first before using the long-press to remove a repeat group. If you leave the repeat_count as is and then use the long-press method to remove a group, when you get to the end of the repeat group it will add on a new repeat instance at the end if you have not already revised the original repeat_count to a lower number.
"index()" and "selected-at()" are functions that you can use in expression. Find out more in our help topic on using expressions in your form designs.
Do you have thoughts on this support article? We'd love to hear them! Feel free to fill out this feedback form.
0 Comments