Advanced: Demo - Model Iterations for item list repeats

Using Item Lists, it is possible to make forms which ask users repeated sets of questions per item in the list. Using "Model Iteration" it is possible to extend this pattern to provide multiple "loops" of questions over an item list, and even reference the user's answers in one set of repeated questions when displaying the next set of questions inside of the form.

Using this Demo

  • Download the lookup tables excel file here and import it into your project space's lookup tables list. You should have a resulting lookup table called "iterables".

  • Next, download the attached XForm here, and Upload that form into your application

  • Make sure to be logged in as a mobile worker to test the form, you will need to be able to access the lookup table.

Demo Notes

Each repeat group has a pattern where the repeat is split into two portions. The first portion is responsible for loading data from either the lookup table or another repeat group. The second portion contains the questions. In the second portion, all data references are "easy" and don't require use of current() or making "relative steps" (like "/../") to other areas. This is an important best practice to follow to avoid complex issues if elements are moved or re-ordered.

Using a single root "Questions" group inside of a repeat allows the repeat to be "Skipped" without being removed, even though the user experience is the same This is a critical pattern for complex logic with repeats.

The calculations for this pattern require using both "native" XPath references ("/data/path/to/question") rather than "easy" references (#form/question), and also require use of current() and relative steps. It is very helpful to have a test form like this to test changes you want to make in isolation outside of the context of much larger, much more complex forms.

It is possible to reference data from previous "loops" of a repeat in Hidden Value calculations, but it isn't meaningfully possible to do the same with default values, since all of the questions are created upfront, and since the user may change the original question after it is created.