Difference between revisions of "SurveyCTO Filtering in Repeated Questions"

Jump to: navigation, search
Line 1: Line 1:
== Best Practice ==<onlyinclude>
This article discusses best practices when editing '''SurveyCTO Filtering in Repeated Questions''' and provides a code example.  
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.</onlyinclude>
== Read First ==
 
* This example demonstrates how to remove already selected options from ''select_one'' fields in repeat groups.
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.  
* 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.</onlyinclude>
* 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 ==
== Code Example ==

Revision as of 13:57, 11 July 2022

This article discusses best practices when editing SurveyCTO Filtering in Repeated Questions and provides a code example.

Read First

  • 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