Example 1
This example asks the user for two dates for a journey--the outward and return parts of the trip. If the customer only wants a single, or one-way ticket we set the value of the return date to nil.
First we set up the model with instance data:
<xf:model>
<xf:instance id="my-order">
<order xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<travel-date>2005-05-07</travel-date>
<return-date xsi:nil="false">2005-05-07</return-date>
</order>
</xf:instance>
Next we indicate the data type of the two dates, and set the return date to only be displayed to the user if the xsi:nil attribute is true:
<xf:bind nodeset="travel-date" type="xsd:date" />
<xf:bind nodeset="return-date" type="xsd:date" relevant="boolean-from-string(@xsi:nil)=true()">
<xf:bind nodeset="@xsi:nil" type="xsd:boolean" />
</xf:bind>
</xf:model>
The user interface for this model is quite straightforward. All we need are normal input controls for each of the three pieces of information we need to collect, and XForms does the rest for us. If the user indicates that they want a return trip (i.e., sets the xsi:nil attribute to true via the check-box) then the second date input is shown:
<xf:input ref="travel-date"> <xf:label>Travel Date:</xf:label> </xf:input> <xf:input ref="return-date/@xsi:nil"> <xf:label>Return trip?</xf:label> </xf:input> <xf:input ref="return-date"> <xf:label>Return Date:</xf:label> </xf:input>
Example 2
Whilst the previous example allows the user to set the nillable value explicitly, this example works the other way round--if the value of an element is '' (the empty string) then the element is set to nil, ensuring that it will pass schema validation.
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>


Recent comments
2 days 4 hours ago
7 weeks 2 days ago
7 weeks 2 days ago
10 weeks 6 days ago
12 weeks 2 days ago
12 weeks 3 days ago
12 weeks 3 days ago
12 weeks 5 days ago
12 weeks 5 days ago
12 weeks 5 days ago