XForms/Binding in Repeats

Motivation
You have a list of items and you want a simple way of conditionally displaying fields within a repeated group.

Method
We will do this is two ways. First we will use a bind expression in the model. The second method of doing this will be to use a group element with a ref attribute.

Sample Data
display 1 display 2 display 3

Solution Using Relative Binds
In this example we use a relative statement to indicate that the field should only be displayed if the code value is "yes". Note that the context of the relevant expression is the result of each nodeset item.

Solution Using Group Element
We can use the ref attribute to conditionally display any field within a repeat. We do this by starting the group ref attribute with "." to give it the current context. Then we add a predicate to turn on or off that entire group. In this case if the code is "yes" the input field will be displayed. If it is not the field will be hidden.

Complete Example
display 1 display 2 display 3 display 4    Test of binding rules within a repeat  Group #   Display Input Field:   Yes yes   <xf:label>No</xf:label> <xf:value>no</xf:value> </xf:item> </xf:select1> <xf:input ref="field" > <xf:label>Conditional Display: </xf:label> </xf:input> </xf:repeat> <xf:output value="index('my-repeat')"> <xf:label>Current Selected Group: </xf:label> </xf:output>