Conditional Clusters

Clusters can also be wrapped in a condition element. If the expression of the condition element does not refer to any of the questions on the same page the cluster is a static conditional cluster. That is because it can be determined before the pages is displayed whether to display the cluster or not.

For example, if information about household members has been gathered you may wish to add another page to ask further personal details including whether the person is pregnant. A new isPregnant attribute should be added to the Person entity to store this information:

Figure 1. Additional Person Attribute
<xsd:element name="Person">
  <xsd:complexType>
    ...
    <xsd:attribute name="isPregnant" type="IEG_BOOLEAN"/>

Of course, this question is only applicable if the gender is female. Therefore the cluster can be wrapped in a condition and it will only be displayed if the condition expression evaluates to true. The new extra Person Details page can be defined as follows:

Figure 2. Static Conditional Cluster
<question-page id="AboutTheClientContinued" entity="Person" ...>
  <condition expression="Person.gender==&quot;SX2&quot;">
    <cluster>
      <question id="isPregnant" mandatory="true">
          <label id="IsPregnant.Label">
              Are you pregnant?
          </label>
          <help-text id="IsPregnant.HelpText">
              Are you pregnant?
          </help-text>
      </question>
    </cluster>
  </condition>
</question-page>

Alternatively, if any of the questions referenced in the condition expression are on the same page, the cluster is then a dynamically conditional cluster. The means that the cluster will be displayed and hidden as the user changes answers to questions on the page. This dynamic feature of IEG requires that JavaScript is enabled in the browser. The expressions of dynamically conditional cluster may not refer to custom functions, as the expressions are evaluated without making a server call.

Without changing the DS schema, if the example above is changed so that the conditional cluster is defined on the same page as the gender question the cluster will be a dynamically conditional cluster.

Figure 3. Dynamically Conditional Cluster
<question-page id="AboutTheClient" entity="Person" ...>
...
  <cluster>
    <title id="DetailsCluster.Title">
      <![CDATA[Personal Details]]>
    </title>
...
    <question id="gender" mandatory="true">
      <label id="Gender.Label">
        <![CDATA[Gender:]]>
      </label>
    </question>
...
  <condition expression="Person.gender==&quot;SX2&quot;">
    <cluster>
      <question id="isPregnant" mandatory="true">
        <label id="IsPregnant.Label">
        <![CDATA[Are you pregnant?]]>
        </label>
      </question>
    </cluster>
  </condition>
</question-page>

The pregnancy question will dynamically appear or disappear when the value selected for the gender changes. Dynamic behavior on a page can be triggered by text fields, date fields, checkboxes, radio buttons, select elements. Dynamic behavior cannot be triggered by the answer to a multi-select question or a question matrix, due to the restrictions of the expression syntax.

It should be noted that only one level of condition is allowed around a cluster, i.e. conditional clusters cannot be nested in other conditions. The condition expression for a dynamically condition cluster may refer to questions on the same page that are themselves defined in dynamically conditional cluster. This creates a cascading dependency between clusters.