You can define a list and later include or exclude a subset of options by using square bracket '[ ]' syntax. This filters both the displayed options and those in the data map.
Inclusion
setlist: SNACKS
1. Pretzels
2. Popcorn
3. Chips
4. Apples
5. Donuts
6. Wasabi Snow Peas
1. Which of these non-fruit snacks do you like?
type: checkbox
optsfrom: SNACKS [1,2,3,5,6]
Exclusion
1. Which of these non-fruit snacks do you like?
type: checkbox
optsfrom: SNACKS -[4]
Details
- To include a subset of a list, reference the desired option IDs and enclose them in square brackets, e.g.,
[1,2,3,5,6]
. - For continuous options, you can also use two dots to define a range (also known as a series) between the first and last number, e.g.,
[1..3,5,6]
. - To exclude options, add a minus sign before the brackets, e.g.,
-[4]
. You can also use ranges for exclusions as needed. - Inclusion/exclusion syntax can be combined with Perl, RegEx, option data, and conditions.
Tip! This article explains the use of syntax with square brackets '[ ]', which differs from the condition
decorator using curly braces '{ }'. While the condition
decorator does not filter options out of the data map, it can control which options are displayed on screen.
Additional examples
With a conditional decorator
A condition decorator can be added after inclusion syntax to further filter options. In this example, the hidden variable BERRY selects up to two berry options (1-4) from FRUITS, but only if chosen at Q2B. Options 5 and 6 are always excluded.
setlist: FRUITS
1. Strawberries
2. Blueberries
3. Blackberries
4. Raspberries
5. Cantaloupe
6. Watermelon
2B. Which of the following fruits do you like?
type: checkbox
optsfrom: FRUITS
BERRY. Select 2 berries.
type: checkbox
maxgroups: 2
selectby: condition
optsfrom: FRUITS [1..4] {if anyChecked($Q2B,[id])}
With option data
Inclusion syntax can work with option data placeholders like '[id]' and '[text]', as well as arbitrary option data stored on the list elements.
In the example below, only the options with IDs greater than 20 will be stored in the data map and shown to the respondent.
setlist: SEA_CREATURES
11. Rocklobster
12. Crayfish
13. Langoustines
14. Prawns
21. American sole
22. Amur pike
23. Black sea bass
24. Golden trout
2. What sort of fish do you enjoy?
type: checkbox
optsfrom: SEA_CREATURES [if [id]> 20]
While the previous example references the system option data placeholder '[id]', this example uses arbitrary option data stored in the MORE_FOODS list. Any option with a '1' in the option data label TYPE will be displayed at Q4.
setlist: MORE_FOODS
1. Apple {{TYPE:1}}
2. Banana {{TYPE:1}}
3. Avocado {{TYPE:1}}
4. Granola {{TYPE:1}}
5. Bacon {{TYPE:2}}
6. Turkey {{TYPE:2}}
7. Pasta {{TYPE:2}}
8. Cake {{TYPE:2}}
9. Waffles {{TYPE:3}}
10. Bread {{TYPE:3}}
4. This question only contains answer options that have a '1' in the field 'TYPE'.
type: radio
optsfrom: MORE_FOODS [if [TYPE]==1]
With Perl and RegEx
Square brackets accept other types of logical statements. The example Q2 above could instead utilize Perl substrings.
With Perl's 0-based index, the logical statement essentially means: "Start at the beginning of the option IDs, move one to the right, and if the value in this position is a '2', include it." Since the fish option IDs range from 21 to 24, this will still return the same options as the conditional statement used in Q2.
2A. What sort of fish do you enjoy?
type: checkbox
optsfrom: SEA_CREATURES [if substr([id],0,1)==2]
Regular expressions, also known as RegEx, work as well. In this example, we use the option data placeholder '[text]' along with a regular expression to check if the option text contains the word 'steak'. If true, options 1 and 2 will be available as answers to Q3, while options 3-5 will be excluded.
setlist: FOODS
1. Beef steak
2. Salmon steak
3. Asparagus
4. Pizza
5. Chicken milanese
3. What's for dinner?
type: radio
optsfrom: FOODS [ if [text] =~ /steak/ ]
Comments
0 comments
Please sign in to leave a comment.