Condition Tag: Create Simpler References to Condition Logic

1: Overview

The <condition> element enables you to declare a named condition. Instead of rewriting condition logic across your entire survey, you can use the <condition> element to write it once and then reference the condition using the element's label.

The condition's name. This is what you will use to reference the condition's logic.

If needed, you can also add builder:warning="unsupported" to flag an element as unsupported and prevent a project from launching.

2.1: cond - Set the Condition

The cond attribute is the logic for the <condition> element. Instead of rewriting the same condition logic across a survey, you can specify the logic inside the cond attribute of a <condition> element and refer to it instead.

Instead of writing the condition Q2.ival ge 18 for both questions Q3 and Q4, we declared a <condition> element named "isAdult" and wrote the condition inside of the cond attribute. With this <condition> element in place, we can refer to the logic using the condition.label syntax (e.g. condition.isAdult) and show both questions Q3 and Q4 appropriately.

2.2: label - Specify the Condition's Name

The label attribute is the <condition> element's name. It's best to set this attribute to a human readable string that can be easily remembered and typed out.

For example:

<condition label="maleTV" cond="Q1.r1 and Q2.r3 and (Q3.r1 or Q3.r2 or Q3.r3)">Males who frequently watch TV</condition>
<condition label="maleGamers" cond="Q1.r1 and (Q2.r4 or Q2.r5)">Males who game via console or PC</condition>
<condition label="femaleTV" cond="Q1.r2 and Q2.r3 and (Q3.r1 or Q3.r2 or Q3.r3)">Females who frequently watch TV</condition>
<condition label="femaleGamers" cond="Q1.r2 and (Q2.r4 or Q2.r5)">Females who game via console or PC</condition>

3: Create a Conditions Table

There is a special mutator function available to automatically create a table in the report containing a row for every <condition> element in a survey.

Add the following to your survey's XML:

<label onLoad="createConditionTable()" />

This will automatically generate a table named "conditions" in the report. For example: