XForms Basics, Part 3 - Money, Money, Money (Page 3 of 7 )
Of course, the "required" attribute is just one example of what XForms calls "model item properties." Another one is the "relevant" attribute, which specifies when a particular element of the instance data is enabled or disabled. Consider the following example:
<!-- form model -->
<xforms:model id="tran">
<xforms:instance>
<transaction>
<type />
<amount />
<checkNumber />
</transaction>
</xforms:instance>
<xforms:bind nodeset="/transaction/checkNumber"
relevant="/transaction/type='check'" />
</xforms:model>
Basically, this says that when performing a transaction (in this case, a bank account transaction which is either a deposit or a withdrawal) the check number is only relevant when the transaction involves a check.
Of course, it's up to the implementation to decide how to handle this particular property. Some implementations might disable the field for data entry during cash transactions, others might hide it, and still others might pop up a warning.
You'll notice, also, that the "relevant" property contains an equality test. Model item properties can contain comparison tests, so long as these conform to the rules laid down for XPath expressions. Here's another example, this one illustrating the use of a comparison test with the previously-explained "required" property by requiring the entry of a tax identification number for transactions greater than $50,000:
<!-- form model -->
<xforms:model id="taxes">
<xforms:instance>
<transaction>
<name />
<amount />
<taxID />
</transaction>
</xforms:instance>
<xforms:bind id="taxIDRequired" nodeset="/transaction/taxID"
required="/transaction/amount > 50000" />
</xforms:model>
Next: Shop 'till You Drop >>
More XML Articles
More By Harish Kamath, (c) Melonfire