The match to
and derive from
tags are streamlined implementations of fetch_cell and fetch_row. They use less verbose syntax, and are therefore easier to read and write. In cases where data is to be pulled in from a spreadsheet, as in a ZIP code look-up, these are the best tools to use. These tags work as a pair. The match to
tag initiates the spreadsheet reference, and derive from
enables specific fields to be referenced.
Note: Widgets featuring a derive from
tag are invisible.
Syntax
Use matchto
on the question containing the value to check against a sheet. Use derivefrom
to get the corresponding column from the matching matchto
row. Closed-end variables utilizing derivefrom
automatically build all options available in the referenced sheet, unless instructed to do otherwise. Additionally, a default value can be assigned if no math is present.
matchto
# Variable with data to check against sheet matchto: Sheet name to match
derivefrom
Basic
# Variable to populate with given column for row matching matchto field's input derivefrom: QID of matchto variable, Sheet column label to return
Default
Use default to specify a selection to use in case no matching items returned.
derivefrom: QID of matchto variable, Sheet column label to return {default: Default option ID here}
Options
Variables with derivefrom
automatically contain all distinct options present in the sheet for the specified column. To override this default and prevent the automatic addition of options from the sheet, use the options
decorator. This requires that options be specified locally, or via an optsfrom
tag.
derivefrom: QID of matchto variable, Sheet column label to return {options: N}
Examples
Sheet
The following examples assume a system sheet named 'system.zip_db_dlxbus' (shown below). Examples for QSTATE and QREGION also refer to system sheets 'system.states' and 'system.rgopts', respectively.
id | State | StateCode | Region |
---|---|---|---|
40003 | Kentucky | KY | South |
40004 | Kentucky | KY | South |
40006 | Kentucky | KY | South |
etc. | etc. | etc. | etc. |
Basic
P6. Please enter your ZIP code:<p> type: text match to: system.zip_db_dlxbus datatype: zip5 maxlen: 5 size: 6 STATE. State type: radio derive from: QP6 StateCode optsfrom: system.states REGION. One of four geographic regions, defined by the U.S. Department of Commerce, Bureau of the Census. type: text derive from: QP6 Region
Default
STATE. State type: radio invisible: y derive from: QP6 StateCode {default: 99} optsfrom: system.states 99. State not found
Custom option text
To customize automatically generated closed-end response options, use a text
decorator.
REGION. One of four geographic regions, defined by the U.S. Department of Commerce, Bureau of the Census. type: radio derive from: QP6 Region {text: The [id] Region} optsfrom: system.rgopts
Options
To prevent the automatic generation of survey fields by derivefrom
, use the options
decorator.
REGION. One of four geographic regions, defined by the U.S. Department of Commerce, Bureau of the Census. type: radio derive from: QP6 Region {options: N} 1. North 2. South 3. East 4. West
Quotas
One can also use derivefrom
variables as quotas.
REGION. One of four geographic regions, defined by the U.S. Department of Commerce, Bureau of the Census. type: radio derive from: QP6 Region {options: N} quotas: y 1. North 2. South 3. East 4. West
Comments
0 comments
Please sign in to leave a comment.