Why a repeat_count value doesn't revise down

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.

  1. Person 1
  2. Person 2
  3. Person 3
  4. 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 it’s own because that would violate our core design principle that it is non-destructive with data.

Yes, you can get rid of the extra repeat instance

Because 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.

Strategies you can use in your forms and in the field

There are strategies you can employ to be more certain of the number of repeat instances which are required. The most basic and flexible would be an unlimited repeat_count for the first group. The tradeoff with unlimited repeat groups is being asked each time whether you want to add a group. Have you seen the table appearance for repeat groups in action? This can give the SurveyCTO Collect users an overview of how many instances are populated, making it easy to review information already captured in that repeat group. Measures like these might save users time having to page back through multiple repeat groups to find what they’re looking for.

The best approach

An elegant form design solution involves eliminating repeat instances that are no longer required in the above case where an integer which is being used as a repeat_count value is revised downward, using relevance. You can do this by applying relevance to the repeat group itself relative to the "index()" value which is compared to the number stored in the integer field (or a number returned by calling "count-selected()" on a select_multiple field). This is illustrated in an easy-to-follow sample form, here.

"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.


Article is closed for comments.