Sheets are data sources hosted in the UI that can function like lists.
define sheet: survey_id.brands
order: [*]translate: n1. Which brands are you familiar with?
type: checkbox
optsfrom: survey_id.brands
This article focuses on how to interact with existing sheets in your survey programming. To learn about creating sheets, see Managing survey sheets.
Details
- Sheets hosted in a survey's Sheets applet are referenced as
survey_id.sheet_id, where 'survey_id' is the survey ID where the sheet is hosted. -
System sheets are referenced as
system.sheet_id. - Sheets from another survey on the same server can also be referenced.
- Sheets can be used in any instance that a list can be used.
- To control order or translation, use the
define sheetwidget. Then, apply theorderandtranslatetags (as shown above). - Like
set lists, sheets support the addition of element decorators, option data decorators, and inclusion/exclusion syntax. - Decorators can also be used as column headers in sheets.
Tip! Sheets hosted in a survey can be referenced by that survey without including the survey ID, e.g., optsfrom: sheet_id.
Additional examples
Referencing a system sheet
If the sheet referenced is a system sheet, reference it as system.sheet_id, as shown below.
1. Pick a color
type: radio
optsfrom: system.colors
Using decorators in a sheet
Like lists, sheets support decorators.
Imagine the 'colors' sheet below is stored in a survey called 'demo' on the same server. The 'colors' sheet has the mandatory 'id' and 'text' columns, in addition to the arbitrary decorators, 'ucfirst' and 'happy'.
| id | text | ucfirst | happy |
| 1 | blue | Blue | 1 |
| 2 | red | Red | 1 |
| 3 | yellow | Yellow | 1 |
| 4 | brown | Brown | |
| 99 | None | None |
Then, the survey references the 'colors' sheet using optsfrom, applying decorators as needed.
-
Q1 & Q2: The
textdecorator modifies option text (e.g., "I like blue" and "I like Blue" instead of "blue"). -
Q3: A
conditiondecorator with square brackets[ ]filters in only colors marked '1' in the 'happy' column.
1. Pick any color.
type: radio
optsfrom: demo.colors { text: I like [text] }
2. Pick a color with a capital letter.
type: radio
optsfrom: demo.colors { text: I like [ucfirst] }
3. Pick a color that makes you happy.
type: radio
optsfrom: demo.colors [ if ([happy]) ]
Tip! For condition decorators with substitutions, use parentheses if the sheet contains blank values, e.g., [ if ([happy]) ] instead of [ if [happy] ], to ensure blanks are treated as 'false'.
Using a sheet in a block
Using the 'colors' sheet from the previous example, we can reference it in a block with the list tag. The example below loops through all items in the sheet, using the 'text' column, while excluding option 99.
block: <<END
1. Do you like %%TEXT%%?
type: radio
1. Yes
2. No
3. Sometimes
END
list: demo.colors -[99]
Comments
0 comments
Please sign in to leave a comment.