5.4 Property required for Mandatory Fields

5.4 Property required for Mandatory Fields

Property required can be used to ensure that the user supplies values for a given field or set of fields. Such mandatory fields may be declared via the schema; in that case, the values are always required. Model property required is for use in those cases where certain fields become mandatory, depending on the input provided by the user when interacting with the XForms application.

The value of property required is an XPath expression that is evaluated to return a boolean value. Like property relevant , it is computed at run-time. When a node in the instance gets required set to true , the user interface is updated appropriately to convey this state. As an example, a visual user agent might use appropriate visual styling to indicate to the user that a certain field is required . Such styling is achieved via the use of CSS3 pseudoclasses :required and :optional , described in Section 5.1.1.

5.4.1 Extending Insurance Form with Property required

Continuing the example of the insurance application form shown in Figure 5.4 and Figure 5.5, we can add bind declarations to the data model to state the following effect. If the user has answered yes to the question

Do you smoke?

then the user must answer relevant questions about existing health conditions; see Figure 5.6. Thus, property relevant causes the needed user interface controls for answering these questions to be presented to the user; property required ensures that the user answers these questions. CSS3 pseudoclasses required and optional style controls to reflect model property required ; for example, fields that are required might be displayed using a different font and color in a visual interface.

Figure 5.6 Property required makes fields mandatory .
 <  model   xmlns  ="http://www.w3.org/2002/xforms"  id  ="i1"  schema  ="insurance.xsd">   <  instance  >     <  person   xmlns  ="">       <  diet  >...</  diet  >       <  habits  >       <  smoker  >false</  smoker  >...</  habits  >       <  health  >       <  chest  /><  heart  /><  lungs  /></  health  >   </  person  ></  instance  >   <  bind   nodeset  ="/person/health">     <  bind   nodeset  ="chest"  relevant  =       "boolean-from-string(/person/habits/smoker)"  required  =     "boolean-from-string(/person/habits/smoker)"/>     <  bind   nodeset  ="lungs"  relevant  =       "boolean-from-string(/person/habits/smoker)"  required  =     "boolean-from-string(/person/habits/smoker)"/> </  bind  ></  model  > 

XForms. XML Powered Web Forms with CD
XForms. XML Powered Web Forms with CD
Year: 2003
Pages: 94

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net