The listUnique
function iterates through a list, checking whether each row-question in a table contains a distinct response. If duplicate a response is found an error message is shown.
set list: BRANDS
1. Brand 1
2. Brand 2
3. Brand 3
3. What is the first word that comes to mind for each brand?
instruct: Please enter a different word for each brand.
type: text table
required: n
size: 30
rowsfrom: BRANDS
validation: listUnique(BRANDS; $Q3R[id]) {message: Please enter a different word for each brand.}
Tip! Not sure which list function is best suited for your needs? Review all list functions here.
Details
-
In its most basic form,
listUnique
accepts two inputs: a list name and a field reference constructed with the '[id]' placeholder. - Options can be filtered in or out of the list with inclusion/exclusion syntax.
- This function is particularly helpful for verifying that text inputs and autoothers do not contain identical responses. It automatically compares the fields that have a response and ignores fields that have not been answered.
Additional examples
Tip! List functions can reference any list type. For derived lists referencing a table, use a leading 'T'.
Validating autoother options
You can also ensure text entered in autoother ("other specify") fields is unique. In this example, the list includes the previous BRANDS list used in the example above, plus three new autoothers. Use [971..973]
to filter autoothers and reference their text fields with QX_[id]_OTH
, where 'X' is the question number, '[id]' is the option ID, and '_OTH' indicates the autoother field.
set list: OTHERBRANDS
optsfrom: BRANDS
971. Other brand {autoother: y}
972. Other brand {autoother: y}
973. Other brand {autoother: y}
4. What other brands can you think of to write in?
instructions: Please enter a few more brands.
type: checkbox
optsfrom: OTHERBRANDS
validation: listUnique(OTHERBRANDS[971..973]; $Q4_[id]_OTH) {message: If you are going to list "other" brands, please do not repeat the same word for each one.}
Ensuring a closed-ended table is unique
Although less common, you can also force every row in a closed-ended table to have a unique response. In the table below, every brand is forced to have a different option selected.
set list: USAGE
1. Never used
2. Used but not within the past 3 months
3. Used within the past 3 months
4. I consider this my main brand
5. This forces you to choose a unique response per row.
instructions: No answer choice here can be repeated.
type: radio table
rowsfrom: BRANDS
optsfrom: USAGE
validation: listUnique(BRANDS; $Q5R[id]) {message: Please recheck the response.}
Comments
0 comments
Please sign in to leave a comment.