This article covers these topics:
Simple choice filtering
You can filter the choices by using simple if .. conditions after each choice, as in the following example:
<question type="single" max_select="1" order="fixed" id="2" text="What is your choice?" alias="Q2">
<choice id="1" label="Red" anchored="false" exclusive="false" alias="" if="answer(Q1)!=1"/>
<choice id="2" label="Blue" anchored="false" exclusive="false" alias="" if="answer(Q1)!=2"/>
<choice id="3" label="Green" anchored="false" exclusive="false" alias="" if="answer(Q1)!=3"/>
</question>
The above example will display the choices of Q2 according to the response to Q1. The logic is as follows:
If the respondent's answer in Q1 is NOT choice 1, then Q2 will display choice 1 Red, and so on.
Advanced choice filtering
The <include> element allows you to incorporate choices from/to another multiple-choice question, single-choice question or shared list. The included choices replace the choice that contains this <include> element.
The IDs of the choices are mapped in the format X:Y, where X is the ID of the original question and Y is the ID of the corresponding choice in the original question the choices were defined in. For example, choice 3 defined in question 5 will always be 5:3 in any question that includes it, no matter how many levels of inclusion). Questions can also be references with their alias, so choice 3 defined in question Q5 will be Q5:3
|
Attribute |
Description |
|
from |
Question reference to include choices from. |
|
include |
Which choice ids to include, defaults to "all choices", which means all choices (other than excluded) are included. To specify many choice list them comma separated. |
|
exclude |
Which choices not to include. To specify many choices, list them comma separated. |
|
filter |
Filtering mode: "true", "false", "and", "or", "replace" , defaults to false (filtering off) |
|
invert |
exclusion filtering (Boolean, default false). |
Filtering mode and inverse filtering
|
Mode |
Description |
|
true |
Filter questions based on the "from" question. If the "from" question includes simple choice filtering, the behaviour depends on the invert attribute. If invert="off" the simple choice condition of the "from" question is ANDed with the current question condition, if invert="on" the simple choice condition of the "from" question is replaced with the current question condition |
|
false |
No filtering performed |
|
and |
The simple choice condition of the "from" question is ANDed with the current question condition (from_q_condition && filtercondition) |
|
or |
The simple choice condition of the "from" question is ANDed with the current question condition (from_q_condition || filtercondition) |
|
replace |
The simple choice condition of the "from" question is replaced with the current question condition (filtercondition) |
Examples
The following script includes all choices from Q1, excluding choice id 1:
<choice id="3" label="going to include not shown">
<include from="Q1" exclude="1"/>
</choice>
The following script includes all choices from Q2, but only shows those choices that were selected in Q2 (equivalent of an "if" condition on the choice):
<choice id="3" label="going to include not shown">
<include from="Q2" filter="true"/>
</choice>