Version Notice: This article covers features in our r9/IS Pro platform. If you're looking for information on this topic related to r8, see Create options tutorial.
Overview
All closed-end questions and tables require options. Options can be defined from spreadsheets, in standalone lists known as setlists, or locally defined on questions and tables. They can be used again later on subsequent questions once they are defined.
Lists are used more broadly in the code, not just to create response options, but also to create batteries for tables or card sorts, to run blocks, and otherwise allow us to reuse information. Lists are especially useful for blocks and loops due to the ability to create option data. This tutorial covers the most commonly used option and list conventions.
Related reading and resources
The following articles can be used for reference with this training module:
Review
Close-ended questions must define options, and the majority of the questions and tables you've created so far have been close-ended. We already used options in both the Create questions tutorial and the Create tables tutorial.
The type
tag determines the functionality of the question, whether text is allowed, numeric input, single selection, etc. How data is stored for a variable/widget depends on the question type or table type. Then, series, lists, or sheets used with the optsfrom
tag or options defined locally determine the answer set, which is the information stored for closed-end data types.
The questions you've created with type: radio
, type: pulldown
, type: checkbox
, or type: listbox
, from the single and multiple choice sections, and almost all of the tables from "Create tables tutorial," generate close-ended data and have option lists. Questions can define options with series
, or by calling one of the lists like SHAPES, PLACE, or COLORS with optsfrom
, and similarly tables can reference the rows defined in a previous table with rowsfrom
. In a few places you've created locally defined (inline) option lists, for instance at A1 and A2F. You also have called in lists used in previous questions by referencing either the question ID (which carries forward logic), like A2D, or referencing the question's inline options/rows (which use the full option list) like at table B5B.
Lastly, close-ended tables encompass both options (the answer set) and the rows or columns used to ask multiple questions. In summary, it's a table containing a series of questions with corresponding options to choose from. Each row or column generates a data point to store data, and the options are the values stored.
Note: The first example of an open-ended question you came across was the autoother at A2B in the Multiple choice questions section of the "Create questions tutorial." As you may recall, the autoother
function adds a text entry box to an "other specify" option. The '97' option itself is part of the closed-end question A2B. When '97' is selected, a response must be typed in, and the captured text is open-ended. The Text entry questions section in the "Create questions tutorial" covers open-ends in greater detail.
Setup
In this section we are going to take a closer look at local options and various ways to work with them. In addition, we will take a closer look at lists, using lists in a variety of ways, including using option data for questions and blocks.
Setup Discussion |
Code Review |
Tag Review |
Options can be defined locally on questions or tables, referred to as inline options. They can also be pulled in from a list with the Tip! Sheets are another form of a list where option data can be organized in columns, like a typical spreadsheet. Consider using sheets for larger lists, such as an extensive brand list, and for lists with several related elements such as a large ZIP code list with state, region, division, and MSA classifications. We will not cover this method in this tutorial. See Creating and editing survey spreadsheets and Using spreadsheets in survey programming for more information. |
This code is needed for this section: setlist: PARTS 1. Petals 2. Stamen 3. Roots 4. Stems |
Lists can be called with any of the
|
Option Piping video
The following video discusses the various ways in which you can "pipe" or reuse the options used with previous survey questions and tables. Local/inline options, setlists (standalone lists), and condition decorators are covered. We recommend you watch this video before continuing with the tutorial.
Local options
The examples in this section cover various ways to manipulate options at the question level known as inline options.
Questionnaire Content | Discussion Details | Coded SPL |
[Keep C1 & C1A on the same page]
|
C1 calls the COLORS list with This example uses include/exclude, +/- Using the include/exclude function actually changes the data structure. If you review the reports for C1, you'll see that only options for the three colors we are including are present. In the the case of C1C (further below), only the first five options are created because we are excluding the last three options. This is quite different from filtering options with |
C1. What flower color do you prefer the most? |
C1A. Which part specifically? |
To keep C1 and C1A on the same page, we added the Note that C1A and C1B both define options directly on the question, known as local (or inline) options. C1A uses the C1A is using a numbering scheme to identify which color for petals or stamen is selected. This type of numbering can be useful for data processing and organization. It can also be helpful for surveys with more complex logic where a Perl sub-string could be used to look at each position in the ID to figure out the color or part. Tip! There is usually more than one combination of tags and widgets that will create what you need. The approach you take depends on the survey. For simpler surveys, it's important to avoid unnecessary complexity; the simpler approach is often the best choice. For more complex surveys, it becomes tricky to introduce more complexity if you have not planned for it in advance. Therefore, design your code to accommodate the specific requirements of the survey you are working on. In the section below, crosslists are used to re-create C1A with the same front-end respondent experience, and the same back-end data storage, but the code is more complex. |
C1A. Which part specifically? |
C1B. Which [Insert C1 Response] flower is your favorite? |
C1B is using an C1B combines answer piping with Perl's lowercase function to make it so the results are lower-cased and blend in with the question text. Without this function, the answer would be piped into the question text as it is, with the first letter of each word capitalized. In certain instances, having capitalized letters mid-sentence may not be ideal. In other cases where you're piping a brand, maintaining the casing could be appropriate and the extra Perl would not be necessary. The 'lc' in the pipe stands for "lower case"; 'uc' can also be used if you wanted to upper case all the letters. |
C1B. Which [* lc($QC1_text) *] flower is your favorite? |
C1C. Of these, what color do you prefer the least for flowers? |
C1C also calls the COLORS list with |
C1C. Of these, what color do you prefer the least for flowers? |
C1D. Rate each part of the plant on a scale of 1 to 5. |
C1D is using the You've used the |
C1D. Rate each part of the plant on a scale of 1 to 5. |
Training Tutorials |
Continue to work in your FLast_r9_intro survey (visit Training tutorials for set up steps) by integrating the new content from each practice section.
Once you finish reviewing each question, add the new content to your survey area via the SPL editor. When the survey compiles successfully, run it in Testmode by clicking the Test 2 button from the compilation screen or open the Test Survey applet from the left navigation menu. Review your survey and test your new questions. After testing your survey, be sure to make any necessary corrections. Then, review the data output by viewing a Response report or creating a new export in Deliverables. Reminder, once you integrate all the new content from this tutorial and test it, publish your survey before moving on to the next tutorial. |
List options
The examples in this section use tags associated with setlist widgets, plus many list conventions covered in Lists overview.
Questionnaire Content | Discussion Details | Coded SPL |
C2. Of the following flowers, which ones have you ever grown?
|
In C2, the instruction uses a combination of options from previous questions and new options. To do this, create a setlist with the Tip! We've already combined multiple lists in the Creating tables tutorial at table B5A and B5B. Here, the 'QC1B.options' used at In addition, this question needs to include an exclusive 'None' option, which is defined locally. |
set list: FLOWERS |
C2A. Do you have any of these flowers in your garden this year? |
C2A is a basic single choice table with Yes/No options defined directly on the table. The |
C2A. Do you have any of these flowers in your garden this year? |
C2B. Of the flowers you have this year, which ones will you grow next year? |
C2B is a standard checkbox question and the instruction wants to only pipe in the options with 'yes' from C2A. To do that, the question will use the same flowers list with an C2B is using the |
C2B. Of the flowers you have this year, which will you grow next year? |
Crosslists
Crosslists are lists built from combining two or more lists, creating a list entry for every potential permutation of options from the source lists. Below we'll discuss how crosslists are created and how the resulting option IDs and option text are denoted in our software. We'll also cover some of the tags that can be applied in conjunction with crosslists.
Questionnaire Content | Discussion Details | Coded SPL |
C1A. Which part specifically?
|
Above in Local Options, C1A has the parts by color written out as local options directly on the question. This is fine for simple questions like this. As complexity is added, it will make things easier to use some of the more advanced features like crosslists. It is possible to organize the code differently with crosslists and accomplish the same outcome. This example re-creates C1A, with the same look and feel, and the same data. The crosslist uses the include syntax to call in the same three options from the COLORS list with '[4,6,8]', and the first two options from the flower PARTS list with '[1,2]'. The option IDs are concatenated, and the ID separator is an underscore by default, (e.g., '4_1'). The The text is also concatenated, so the text is comma separated by default, (e.g.,"Orange, Petals''). Adding the In your FLast_r9_intro code, replace C1A from earlier in this section with this crosslist example. Note: Crosslists are commonly used for gender by age nested quotas and have many useful applications. |
setlist: COLOR_PARTS |
C3. Now we want to get a sense for how and where you encounter flowers. Take a moment to think about a typical day. Where do you typically enjoy flowers? |
In this example, C3 uses the new crosslist AREAS, which combines places and locations using the The crosslist uses include syntax, with the PLACE list to call in the specific IDs needed, and combines that with the options defined at the SIDE list to create the option set for the question. Again, the Tip! The text displayed in the various reports, both on-screen and in exported files, is derived from the question and answer option text. To change this text, use the |
setlist: SIDE |
Element decorators
The examples in this section use tags from the setlist widget, plus many list conventions covered in Lists.
Lists offer a means to reuse information instead of rewriting it each time it's needed. This not only helps minimize the risk of errors but also paves the way for streamlining the survey source code significantly.
Let's take a closer look at how lists let us define data and use elements to modify question defaults. First a quick review of different areas.
An option data decorator, or option data, is added to an option on a list with double curly brackets '{{DTXT: something here}}'. The info added as option data can be used with questions, tables, blocks, and loops.
- For questions and tables, option data is referenced with square brackets as '[DTXT]', in a similar fashion to '[id]' and '[text]'.
- For blocks, it is referenced with the block sigil as '%%DTXT%%', similar to using '%%ID%%' and '%%TEXT%%' in blocks.
- For loops, it's referenced with tildes as '~DTXT~', similar to using '~id~' and '~text~'.
List or element decorators are defined with single curly brackets. There are a handful to choose from, each providing a different function. Let's quickly review some of the more common decorators:
-
{text: }
is used to override the option text. -
{desc: }
is used to override the report text. -
{explain: }
is used to add hover text ("tooltips") to your options. - An
{if }
condition is used to add logic. -
{weight: }
is commonly used to add priority to selections for quotas and theselectby
tag.
Questionnaire Content | Discussion Details | Coded SPL |
C4. Pick the flowers you want to use.
|
Review the element decorators. C4 creates a statement for each of the 12 options from the FLOWERS list using default option data, the '[id]' and '[text]' iterators (placeholders). This question will have options that read 'Flower 1 is a California Poppy,' 'Flower 2 is a Desert Mallow,' 'Flower 3 is a Marigold' and so on for each one. |
C4. Pick the flowers you want to use. |
C4A. Which tree flowers are you familiar with? |
C4A creates a statement for each option from TREE_FLOWERS; in addition, the image will show under the statement. Here we leverage image tags and decorators to avoid manually writing out the HTML for each image. The size and placement of the image can be managed using additional decorators as detailed in the Image tags article. Note: To upload these images, follow the steps in the Adding images to a survey article. |
set list: TREE_FLOWERS |
Comments
0 comments
Please sign in to leave a comment.