Property span class="docEmphasis"constraint/span for Dynamic Validation

5.6 Property constraint for Dynamic Validation

Model property constraint can be used to declare validity constraints to be evaluated during user interaction. These serve to refine the static constraints defined via XML Schema. Property constraint takes an XPath expression that is evaluated to return a boolean value. XForms user interface controls can be styled to reflect the state of this model property via CSS3 pseudoclasses :valid and :invalid. See Section 5.1.1.

Property constraint is especially useful in constraining the cardinality of node-sets used with repeat; this usage will be described separately in Section 5.7. Additionally, property constraint is useful in creating XForms user interfaces where values provided by the user can be used in computing additional constraints on the remaining fields in a form.

5.6.1 Constraining Travel Dates Using constraint

Consider a travel application that needs to collect departure and return dates. The XForms author can use property constraint to declare that the return date must come after the departure date and that the departure and return dates may not be the same. XForms extends XPath with the functions needed to perform such date comparisons; see Figure. Function days-from-date takes a string representing a value of type xsd:date and returns the number of days since January 1, 1970. We use this function to compute the number of days between the departure and return dates in property constraint.

Figure Constraining return date via property constraint.
<model id="t" xmlns=""
    <trip xmlns="">
      <depart xsi:type="xsd:date"/>
      <return xsi:type="xsd:date"/>
  <bind nodeset="/travel">
    <bind nodeset="return"
    - days-from-date(depart) &gt; 0"/>

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows