Repeating fields
For a household roster, you often want to collect answers to the same questions for each member of the household. Similarly, in a consumption module, you might want to ask certain questions about each item consumed. For a facility inspection, you might want to ask a certain set of questions about a series of rooms. It turns out that there are many such cases, where you want to repeat the same set of questions x times, where x can be anywhere from 0 to many. (This is sometimes called "looping" or, in a paper survey, collecting data in a "table" or "grid".)
You have three basic options for how to collect this kind of repeated data in a survey form:
- Add lots of duplicate fields to your survey. With this approach, if you wanted to record the name for each of up to 10 household members, for example, you would create a field for each. So, e.g., fam_name1 would ask about the first family member's name, fam_name2 would ask about the second member's name, and so on, up to fam_name10. (Tip: in order to streamline the survey for those filling it out, you could first have a field that asks for the number of family members, then each fam_name field could have a relevance column to indicate that fam_name question prompt should show only when appropriate. For example, the fam_name3 field's relevance column might include "${numfamily} >= 3" if the number of family members had been recorded in a field named "numfamily". That way, surveyors don't need to deal with lots of irrelevant prompts.)
- Use repeat groups to ask a group of questions repeatedly, until the user indicates that he or she is done. This method is the quickest to implement in your survey form – simply surround a group of questions with begin repeat and end repeat rows – and it offers the greatest flexibility for those filling out your form. Users can sometimes find the experience a bit challenging, however. For example, they might accidentally add another group at the end of a roster, even when they are really finished. If they do, they can then remove that group manually (mobile users press-and-hold on a question in the group, web users use the Options menu), but it's easy to get confused.
- Use repeat groups to ask a group of questions repeatedly, but control the number of repetitions. This is a kind of hybrid approach that simplifies the user experience for those filling out surveys, but requires a bit more work from you, the form designer. Here, you use begin repeat and end repeat rows like above, but then you specify either a fixed number (like "3") or a prior field (like "${numfamily}") in the begin repeat row's repeat_count column. The group of questions will then repeat exactly the number of times you have configured them to repeat.
The main advantage of Option 1 is its simplicity. First, you might prefer the way that non-repeated data gets exported in a simple "wide" format; with only one possible response per field per submission, all data is exported in a single export file, with a structure that doesn't change from export to export, and which can be easily mail-merged into Microsoft Word if you so desire. Second, if you have a separate field defined for each response, then you can very easily refer to those responses from anywhere in your form (e.g., a later field's label can be something like "What is ${fam_name3}'s age?"). Within the same repeat-group, referencing fields is also simple (as in "What is ${fam_name}'s age?" when the fam_name field is within the same repeat group), but referencing repeated fields becomes slightly more complicated from outside those fields' original repeat groups (you need to use the indexed-repeat() function). Of course, the costs to Option 1 are lots of careful copying-and-pasting, a much longer form, and a hard limit on the number of different entries your form will accept.
Options 2 and 3 do have a fundamentally different data structure, because repeated fields can have more than one response per submission. But both the server and SurveyCTO Desktop can re-format repeated data from "long" to "wide" format (see Understanding the format of exported data for a full discussion). Really the only thing you lose with Options 2 and 3 is the ability to mail-merge data into Microsoft Word.
The following sample forms demonstrate these different options: