Guide to choice filters

In SurveyCTO forms, you can collect categorical data using pre-coded response options (or “choice lists”) in fields that take a single or multiple response (in either a select_one or select_multiple field). Choice lists can also be dynamically filtered based survey logic you apply to fields. This filtering happens using a.) optional “filter” values added to a choice list that work with b.) a choice_filter expression that is applied to a select_one or select_multiple field that is using that choice list.

A choice_filter expression is instructions for filtering a choice list based on choice list filter values, associated with the field (rather than the choice list itself). Typically, choice lists are filtered using prior responses as filtering criteria. For example, in an agriculturally themed survey, you might have a question about what crops will be grown by a respondent next season, and it could make sense to filter that list based on the upcoming season.

Outside choice filtering, choice lists will be static with every choice appearing each time the form is completed.

Getting started

As above, to introduce choice filtering to your form design, you need to a.) give a choice list filter values and b.) give a field that uses that choice list a choice_filter expression. In the online form designer, when you configure a select_one or select_multiple field to define additional field properties, at the top of the configuration screen that opens, you’ll be able to select an existing choice list or create one and give it filter values:

choice_filter_list.gif

From the video, the steps are:

  1. Add a field and give it a label.
  2. Select a field type for the field (either select_one or select_multiple).
  3. Configure the field.
  4. Name the field (named “crops” in the video).
  5. Create and name your new choice list (also named “crops” in the video).
  6. Give each choice a label, value and filter value (in this example, the filter values are choice list values from a prior field - with values “summer” and “winter”). 
  7. Save each choice as you work.
  8. Save the choice list once you’re done adding choices.
  9. Click on More options… at the bottom of the field configuration interface.
  10. Scroll down to the bottom of the field configuration window to add a choice_filter expression (in this example, “filter = ${season}”).
  11. Save the field.

What happened there?

In this scenario, in an agriculture setting, I have a list of crops which I want to filter based on the upcoming season. If the next season is summer, I only want to display summer crops. If the next season is winter, I only want to display winter crops.

First, I needed to find out what season it will be, so the answer is recorded in a select_one field named “season”, with the choice list values “summer” and “winter”. Then, in the “crops” choice list used by the “crops” field, I apply filter values equal to the corresponding choice list values in the “season” field (matching the crops in the choice list, with the corresponding season). The filter values in conjunction with a choice_filter expression, “filter = ${season}”, means that only the choices in the “crops” choice list with a filter value equal to the value stored in the field, “season”, will be displayed.

This might also be easier to understand when looking at the “season” and “crops” choice list on the choices sheet of the form design template:

choices_sheet_filter_example.png

In the above screenshot, we can see two choice lists named “season” and “crops”, identified by the fact that these values are repeated for each choice in that list in the list_name column of the choices sheet. As in all choice lists, each choice has a unique set of values with corresponding labels that appear on screen while completing the form. Notice that the values in the “season” choice list are repeated in the filter column of the “crops” choice list - this is the association between the two choice lists that facilitates filtering of the choice list for the “crops” field based on the values stored in the “season” field.

What isn’t visible in the screenshot above is that on the survey sheet, the “crops” field has this choice_filter expression:

filter = ${season}

This article is the first part of this feature guide. Click here to read part 2 on additional properties and considerations for choice_filter expressions. You can also jump to the last part to see working examples by clicking here.

0 Comments

Article is closed for comments.