XForms-Transitional Testbed - validation expressions

This is part of a series of cross-platform experiments in incremental extensions to HTML4 forms that provide a stepping stone towards the much richer capabilities in XForms. This particular experiment introduces a constraint attribute whose value is an expression that can act over form fields. If it evaluates to false then the field's value is invalid. The attribute is useful when the value allowed for one field depends on the value of another field.

Please view the XForms-Transitional script for more details on how this works.

Validation expressions

Here is the markup for the above form:

<form name="form1" onsubmit="false">
<legend>Validation expressions</legend>
<label for="f1" title="must be a number">X</label>
<input id="f1" name="x" datatype="number"/>
<label for="f2" title="must be a number greater than x">Y</label>
<input id="f2" name="y" datatype="number" constraint="y &gt; x"/>


Field names can be used within expressions and are evaluated in the scope of the form for the associated field. Certain characters should be represented as entities, essentially this means that you should use &lt; for <, &amp; for & and &gt; for >. This isn't strictly necessary for documents delivered as text/html. Expressions can also reference global variables and functions. The attribute name "constraint" was chosen for consistency with XForms. Note that field validation occurs after all dependent fields have been updated. The validation attributes (type, constraint, min, max, and pattern) may be used with calculated fields.

Dave Raggett <dsr@w3.org>