Created
October 19, 2011 16:56
-
-
Save terrancesnyder/1298931 to your computer and use it in GitHub Desktop.
XForms Validation / Binding Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
The constraint Property: | |
When evaluating to XPath false, the associated model item is not valid; | |
the converse is not necessarily true. This model item property does not prevent | |
form controls and XForms actions from setting invalid values into data nodes. | |
Example: | |
Here, a constraint property associated with element my:to indicates | |
that its value must be greater than that of element my:from. | |
--> | |
<instance> | |
<my:range> | |
<my:from /> | |
<my:to /> | |
</my:range> | |
</instance> | |
<bind nodeset="my:to" constraint=". > ../my:from" /> | |
<!-- | |
The calculate Property: | |
An XForms Model may include model items whose string values are computed from other values. | |
For example, the sum over line items for quantity times unit price, or the amount of tax to | |
be paid on an order. The formula for such a computed value can be expressed with a calculate | |
property, whose XPath expression is evaluated, converted to a string with the XPath string() | |
function, and stored as the value content of the calculated data node. | |
Example: | |
Here, we have associated a relevant property with element my:discount | |
to indicate a discount of 10% is relevant when the order amount is greater than 1000. | |
--> | |
<instance> | |
<my:order> | |
<my:item> | |
<my:amount /> | |
<my:discount /> | |
</my:item> | |
</my:order> | |
</instance> | |
<bind nodeset="my:item/my:discount" calculate="../my:amount * 0.1" | |
relevant="../my:amount > 1000"/> | |
<!-- | |
The relevant Property: | |
Many forms have data entry sections that depend on other conditions. For example, a form | |
might ask whether the respondent owns a car. It is only appropriate to ask for further | |
information about their car if they have indicated that they own one. | |
Example: | |
Here, we have associated a relevant property with element my:discount | |
to indicate a discount is relevant when the order amount is greater than 1000. | |
--> | |
<instance> | |
<my:order> | |
<my:item> | |
<my:amount /> | |
<my:discount>100</my:discount> | |
</my:item> | |
</my:order> | |
</instance> | |
<bind nodeset="my:item/my:discount" readonly="true()" | |
relevant="../my:amount > 1000"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.w3.org/TR/2009/REC-xforms-20091020/#model-prop-calculate