Difference between revisions of "SurveyCTO Dynamically Populated Choice Lists"
Line 1: | Line 1: | ||
This article discusses best practices when editing '''SurveyCTO Dynamically Populated Choice Lists''' and provides a code example. | |||
== Read First == | |||
* Sometimes we want to ask a respondent to select one or several answers out of answers the respondent have given earlier in the interview. | |||
* For example, we might want to ask who in the household out of the household members listed in the household roster module is currently employed. | |||
* It is possible to do this by dynamically load previous answers as answer options. | |||
== Best Practice == | |||
Any answer can be used in dynamic choice lists, but when using variables inside a repeat group, one more extra step is required because we cannot reference a field that was inside a repeat group directly. We ned to first store the value of this field so that SurveyCTO knows what is the item we are referring to. The calculate field is the intermediate step required. The same applied if you want to build a relevance with the value of a field that filled inside a repeat group. | Any answer can be used in dynamic choice lists, but when using variables inside a repeat group, one more extra step is required because we cannot reference a field that was inside a repeat group directly. We ned to first store the value of this field so that SurveyCTO knows what is the item we are referring to. The calculate field is the intermediate step required. The same applied if you want to build a relevance with the value of a field that filled inside a repeat group. | ||
Revision as of 13:50, 11 July 2022
This article discusses best practices when editing SurveyCTO Dynamically Populated Choice Lists and provides a code example.
Read First
- Sometimes we want to ask a respondent to select one or several answers out of answers the respondent have given earlier in the interview.
- For example, we might want to ask who in the household out of the household members listed in the household roster module is currently employed.
- It is possible to do this by dynamically load previous answers as answer options.
Best Practice
Any answer can be used in dynamic choice lists, but when using variables inside a repeat group, one more extra step is required because we cannot reference a field that was inside a repeat group directly. We ned to first store the value of this field so that SurveyCTO knows what is the item we are referring to. The calculate field is the intermediate step required. The same applied if you want to build a relevance with the value of a field that filled inside a repeat group.
Coding Example
Here is a code example of how the answers to a field inside a repeat group are used to dynamically load the answer options for a select_one or a select_multiple question.
This example dynamically loads answers from a repeat group to be able to use them later in the questionnaire: as relevance, or dynamically populated choice lists for example. If you were to dynamically load answers from fields not inside a repeat group, then you simply reference those fields directly in the choice tab.
Note that this coding example can be improved in many ways. It has excluded some possible improvements in order to highlight the functionality discussed in this article. The most obvious improvement would be to filter the answer options so that only the answer options needed are displayed. See the section about choice filters.
Note that SurveyCTO will let you upload a form on the server even if you used directly an answer from a repeat group in your programming without referring it with a calculate field. The error message will appear only on the tablet, when swiping to the next question. In that respect, always test your form before the field data collection.
Back to Parent
This article is part of the topic SurveyCTO Coding Practices