Previous Next

To open or use this sample form, go to the Design tab, scroll down to the Your forms and datasets section, and click + then Start new form; then enable Use a sample form as your starting point and choose Rosters: Collecting repeated information with multiple repeats from the list. You can also click here to download the spreadsheet form definition.

In the spreadsheet form definition, you will find two groups of repeated questions, with the second group referring to answers from the first. The first group asks for all family members' names, and the second follows up to ask, later, about all family members' ages.

After consenting to participate in the survey, the user will be prompted whether they want to add a family member:

If the user chooses to add a group, the following question will appear:

After entering the name of one household member, the user will then be prompted whether or not another household member should be added:

And if the user chooses to add another household member, the following question will appear:

Following is how the workbook appears for this portion of the survey. You will notice that the label in the begin repeat row is the same as the text within the quotation marks in the "Add New Group?" pop-up above.

typenamelabelcalculation
begin repeatnamesHH member names 
calculatenamenumber index()
textnameWhat is the name of household member #${namenumber}? 
end repeatnames  

You can see that index() has been used as the calculation expression for the calculate field (see discussion of the index() function in Using expressions in your forms). This function returns the index or repetition number for the current repeat group; in this case, it is used to identify the number of the current family member, which is used in the label for the name field.

Returning to the survey, when the user chooses not to add any more family members, the following question will appear to ask about the first household member's age:

This question will repeat the same number of times as the previous one, and it will dynamically integrate the name for each family member that was entered earlier. This is how the workbook appears for this repeated question:

typenamelabelcalculationrepeat_count
begin repeatagesHH member ages count(${names})
calculatenamefromearlier indexed-repeat(${name}, ${names}, index()) 
integerageHow old is ${namefromearlier}?  
end repeatages   

Note that you may need to scroll right in the workbook in order to see the calculation and repeat_count columns.

In the repeat_count column, the count() function is used so that the second group repeats exactly the same number of times as the earlier names group repeated (i.e., so that it collects one age to go with every name entered earlier).

In the calculation column, the indexed-repeat() function is used to pull the earlier-entered name to go with each age. This allows the names gathered earlier to be integrated into the labels for the later questions about family member ages.

To read more about these and other functions available for calculations, see Using expressions in your forms.

An example with nested repeat groups

Click here to download a more complex, nested version of this sample form.

The more complex version of this sample nests repeat groups three levels deep, asking about families, then, within each family, about household members, and then, within each family member within each family, about each pet. Finally, ages are collected in a second set of nested repeat groups. (This is a much more complex example, but it might be helpful if you are designing, for example, a form that collects information on agricultural plots and then, within each plot, on the crops planted on that plot.)

Previous Next