xforms:switchAdded by IBM on August 8, 2013 | Version 1 (Original)
|Divides a portion of the form into sets of items, and then controls which set is shown to the user. For example, you may have a form page with Basic and Advanced settings, and may only want to show one type of settings to the user at any given time.
The switch option uses the xforms:switch element to group the items into sets. Each set can contain any number of XFDL items, which are written normally as children of the xforms:switch.
To change which set of items is displayed, you must use the xforms:toggle action.
Note: there can be any number of xforms:case elements, each containing its own set of items.
Table 1. xforms switch parameters
<xforms:switch id="name" single_node_binding xfdl:state="state">
<xforms:case1 id="name" selected="boolean"
<xforms:casen id="name" selected="boolean"
|name||string||an arbitrary name that you assign to the switch or case. All names assigned to id attributes must be globally unique within the form.|
|single node binding||string||optional. See Single node binding.|
|state||XPath|| optional. An XPath expression that is evaluated relative to the single node binding (if given) or the context node of the switch. If this resolves to a node that contains the ID of an <xforms:case>, then that case is active and shown to the user. Otherwise, the xforms:case with a selected attribute of true is shown.
The selected case and the state node are synchronized (that is, changing one changes the other).
|boolean||Boolean||true indicates the case is active (that is, the one shown to the user); false indicates the case is not active.
Note that only one case can be active within a single switch.|
|XFDL items||XFDL||the items that are displayed to the user if the case is active.|
Example This example shows a switch that contains two cases: one if the user is single, and another if the user is married. The first case simply contains a label that informs the user that no additional information is necessary. The second case contains a number of fields that request some information about the user's spouse. To begin with, the items for the single case are displayed on the form, since it is selected (that is, selection = true).
In addition, the following code shows a button that uses the xforms:toggle action to change the switch to show the married case. Note that the xforms:toggle is enclosed in an xforms:trigger, which is activated when the button is clicked and triggers the toggle action.
<xforms:case id="single" selected="true">
<xforms:case id="married" selected="false">
<xforms:label>Enter your spouse's name:</xforms:label>
<xforms:label>Enter your spouse's age:</xforms:label>
<xforms:toggle case="married" ev:event="DOMActivate"
- An xforms:switch can contain any number of xforms:case elements, which can in turn contain any number of XFDL items, including panes (with groups and switches) and tables (with repeats).
- To change which case is selected, you must use the xforms:toggle action. For more information, see xforms:toggle.
- An xforms:switch is not allowed in an xforms:repeat element.