XForms-Tiny - relevant fields

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 relevant attribute which can be used with input and fieldset elements to indicate whether the associated fields are currently relevant. The attribute value is an expression that can act over form fields, and is useful when a certain set of data needs to be collected if another field has a particular value.

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

Relevant fields

Here is the markup for the above form:

<form name="form1" onsubmit="false">
<legend>Relevant fields</legend>
<label title="try with 5 and then with 3"
for="f1">Number of years at current address?</label>
<input id="f1" name="x" datatype="number"/><br/>
<label title="Needed if years at current address is less than 4"
for="f2">Number of years at previous address?</label>
<input id="f2" name="y" datatype="number" relevant="x &lt; 4"/>


The library sets "irrelevant" as a class value when the expression given with relevant attribute evaluates to false. This can be used with CSS style sheets to hide irrelevant sets of fields with the appropriate rules for fieldset, input and label elements, etc. The library also excludes irrelevant fields from submitted data by setting them to disabled. Note that the style sheet sheet may be used to suppress borders on fieldset elements if so desired.

Dave Raggett <dsr@w3.org>