SurveyCTO Filtering in Repeated Questions

Revision as of 11:27, 5 April 2018 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Best Practice

This example demonstrates how to remove already selected options from select_one fields in repeat groups.

It can have several applications in practice, such as choosing a favorite something, 2nd favorite, … etc , or programming in flexibility about the order in which the respondent answers questions about a particular plot, crop, family member, etc.

It’s important that the repeat_count is always well defined, as using up all the answers will result in the form not allowing you to progress.

Code Example

Here is a code example. Here we have a situation where a team is going out to map the plots of an association, but first they want to know which order they will map the 10 plots.

To set this up, we have a repeat group with a select_one field to choose the 1st plot mapped. In the choices tab, the values have corresponding values in the filter.

The choices become filtered after each repetition through the expression not(selected(${plot_order}, filter)) in the choice_filter column. This filters away choices that have already been selected for this question in previous repetition. Note that SurveyCTO aggregates over each instance of ${plot_order} in this filter expression, despite each of them being an individual select_one.

The example includes a join() of the responses that dynamically updates, to help visualize how the filter is being populated.

Note that this could be coded without a repeat group, with the size of the filter increasing with each plot selected.

Back to Parent

This article is part of the topic SurveyCTO Coding Practices