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 Table row validation and column validation.
The row validate
and column validate
tags (alias row validation
and column validation
) are extensions of the validate
tag for use in tables. Use row or column validations to apply a validation individually to every row or column of a table.
Syntax
As with standard validations, row and column validations consist of a condition followed by a message
decorator.
Both the condition and the message support the use of option data such as [id]
or [text]
. The validation will be iterated across the row or column list, and the ID or text (or other option data) will be substituted. This is the key feature that distinguishes these tags from standard validations. Row and column validations can only be added to tables – the question must have a row or column list for the validation to iterate over.
row validate: [condition] {message: message text if condition not met} column validate: [condition] {message: message text if condition not met}
Multi-line validation
Row and column validations may also be written with the message on a separate line below the validate condition. Use the row validate condition
(alias rowval
) and row validate message
(alias rowmsg
) tags for this format. Column validations work in a similar manner, instead using column validate condition
(alias colval
) and column validate message
(alias colmsg
).
# separate line column validation conditions and messages
col validate condition: [condition] col validate message: [message]
# using colval/colmsg aliases colval: [condition] colmsg: [message]
# separate line row validation conditions and messages row validate condition: [condition] row validate message: [message]
# using rowval/rowmsg aliases rowval: [condition] rowmsg: [message]
This format allows for the use of Here documents (heredoc) so that complex conditions can be written on multiple lines, which helps with code readability. See the example below.
Examples
No more than two options checked per row
The following example allows respondents to select up to two (2) options per row. If the respondent selects more than 2, the row validation condition will be violated, and the validation message will be shown, prompting the respondent to "not select more than 2 attributes" for a given row element. Note the row validation message contains [text]
to pipe the specific row option text into the displayed message(s).
10. Please select up to two attributes you feel most exemplify each brand. type: checkbox table row validate: countChecked($Q10R[id]) <= 2 { message: Please do not select more than 2 attributes for [text]. } 1. Texture 2. Saltiness 3. Nutty flavor 4. Consistency 5. Aroma rows: 1. Skippy 2. Jif 3. Peter Pan 4. Planters 5. Store brand
No more than two options checked per column
The mechanics for a column validation work in a similar fashion, but in the context of vscale ("vertical") tables. In such cases, the table generates data points by column, rather than by row. The column validation allows SPs to check a condition against each one of the column's selections.
11. Please select up to two attributes you feel most exemplify each brand. type: checkbox table vscale: y col validate: countChecked($Q11C[id]) <= 2 { message: Please do not select more than 2 attributes for [text]. } 1. Texture 2. Saltiness 3. Nutty flavor 4. Consistency 5. Aroma cols: 1. Skippy 2. Jif 3. Peter Pan 4. Planters 5. Store brand
Multicolumn table
Note: If your table has multiple columns, the row validate
tag must be added to the table root. That is, the row validate
tag should not be added below any --
column separators.
In this example, respondents must give an assessment of a brand in column B if they are familiar with it in column A. The enableWhen
tag is included on column B so that it is only available when respondents indicate familiarity with one of the brands (selecting options 2-5) in column A.
Note that because this is a multicolumn table, start table / end table syntax is needed instead of simple table syntax.
set list: BRANDS 1. Skippy 2. Jif 3. Peter Pan 4. Planters 5. Store brand start table: 12 intro: For each brand you're familiar with, please rate your assessment on a scale of 1-5. rows from: BRANDS row validate: !(anyChecked($Q12R[id]CA,2..5) and noneChecked($Q12R[id]CB,1..4)) { message: Please give an assessment of [text] since you are familiar with it. } -- column id: A Type: radio heading: Awareness 1. Not at all familiar 2. Slightly familiar 3. Somewhat familiar 4. Very familiar 5. Extremely familiar -- column id: B enablewhen: anyChecked($Q12R__RID__CA,2..5) Type: radio heading: Assessment required: n 1. Awful 2. Mediocre 3. Good 4. Exceptional end table
Applying multiple row validations
Multiple row validations may be applied to a table by defining them in a heredoc within the row validations
tag. Line spaces are required between each set of conditions and messages within the heredoc since the tags are repeated.
In this example, the first two validations ensure that a text response is entered in the column corresponding to the radio option selected. Then, the third and fourth validations ensure that a text response is not entered in the column that doesn't match the radio option selected.
set list: GROCERYSTORES 1. Trader Joes 2. Costco 3. Publix start table: 13 intro: For each store, indicate if you shop there. If you do, please specify the reason for shopping. If you don't, specify the reason you aren't a customer. row validate: not (anyChecked($Q13R[id]CA,1) and $Q13R[id]CB eq '') { message: For stores you DO shop at, please specify your reason in the "why" column. } row validate: not (anyChecked($Q13R[id]CA,2) and $Q13R[id]CC eq '') { message: For stores you DO NOT shop at, please specify your reason in the "why not" column. } row validate: not (anyChecked($Q13R[id]CA,1) and $Q13R[id]CC ne '') { message: For stores you DO shop at, please do not specify a reason in the "why not" column. } row validate: not (anyChecked($Q13R[id]CA,2) and $Q13R[id]CB ne '') { message: For stores you DO NOT shop at, please do not specify your reason in the "why" column. } rowsfrom: GROCERYSTORES -- column id: A type: radio 1. Do shop there 2. Never shop there required: y -- column id: B type: text size: 15 required: n heading: Why do you shop there? -- column id: C type: text size: 15 required: n heading: Why don't you shop there? end table
Heredoc condition example
In some situations, validation conditions can be lengthy. To improve code readability, use a multi-line row or column validation with a heredoc at the condition. This allows for line breaks within the condition itself.
In the example below, the numeric responses in Q16 are validated to check that they fit in the range selected at Q15, requiring a lengthy condition. A heredoc is used to separate the condition onto multiple lines, based on the expressions between each or
operator.
setlist: STORES 1. Flatley and Sons 2. Brandi's 15. How many times did you shop at the following retailers last year? type: radio table rowsfrom: STORES 1. 1-5 2. 6-10 3. 11+ 16. To the best of your knowledge, what is the specific number of times you shopped at each retailer last year? type: number table ap: n maxlen: 2 rowsfrom: STORES row validate condition: <<END (anyChecked($Q15R[id],1) and $Q16R[id] >= 1 and $Q16R[id] <= 5) or (anyChecked($Q15R[id],2) and $Q16R[id] >= 6 and $Q16R[id] <= 10) or (anyChecked($Q15R[id],3) and $Q16R[id] >= 11) END row validate message: You said you shopped at [text] $Q15R[id]_text times. Please make sure your specific number is within that range.
Comments
0 comments
Please sign in to leave a comment.