| XForms element XForms defines a small number of such model properties that can be used to express dynamic constraints. These properties, in contrast to constraints expressed via XML Schema, are dynamic and are recomputed during user interaction; their updated value is immediately reflected in the user interface. The dynamic nature of model properties is key to creating online forms that exhibit a high degree of interactivity. Model properties are authored via element During user interaction, it may be useful to indicate that a certain piece of data is required in order to ensure successful completion of a task; this is enabled via boolean property required , described in Section 5.4. Properties relevant and required can be used in combination in creating sophisticated electronic work-flow applications. As an example, the user's response to an initial set of questions can be used to determine the value of relevant on portions of the model; this automatically enables portions of the user interface that bind to the fields that are relevant . Setting property required to true on these relevant fields can in turn ensure that the user gets appropriate feedback when interacting with the associated controls. Finally, boolean property readonly , described in Section 5.5, enables certain fields to be made temporarily read-only during user interaction. This feature can prove extremely useful in work-flow applications where users with different roles work on the same form. Complex forms can express dynamic validity constraints that are computed from the state of the current data instance; for example, a shopping application might declare that to obtain a discount, the user must buy a specific number of items. Dynamic constraints are expressed via property constraint described in Section 5.6. In addition, XForms authors can constrain the cardinality of a given set of nodes ( e.g., the number of items in a shopping cart) by creating model properties that constrain the number of nodes in a set via property constraint . XForms enables the automatic computation of nodes in the data instance; we saw an example of this in the shopping cart application in Figure 4.10. Model property calculate is used to achieve this functionality and is described in Section 5.8. Finally, model property type enables XForms authors to extend schemas that cannot be modified; such external schema augmentation is enabled by property type , described in Section 5.9. 5.1.1 Model Properties and CSS StyleThe purpose of the XForms user interface is to convey the state of the XForms model to the user at all times. Toward this end, the current value of model properties required , relevant , readonly , and constraint for a given node in the instance tree need to be reflected in the user interface. Thus, if a field is presently read-only , it is useful to convey this information, perhaps by styling controls bound to that field using a particular presentation style. There are also boundary conditions where the XForms model and user interface might be out of sync, for example, when a Figure 5.1 Conveying that model and user interface are out of sync via styling.< html xmlns ="http://www.w3.org/1999/xhtml"> < head > < model xmlns ="http://www.w3.org/2002/xforms" id ="sound" schema ="units.xsd"> < instance > < settings xmlns =""> < volume xsi:type ="percentage"/> </ settings ></ instance > </ model > < style type ="text/css"> @namespace xf url(http://www.w3.org/2002/xforms); /* blue background for out of range form controls */ *:out-of-range {background-color:blue; } </ style ></ head > < body > < group xmlns ="http://www.w3.org/2002/xforms"> < range ref ="/settings/volume" start ="25" end ="75" step ="5"> < label >Adjust Volume</ label ></ range > < trigger ev:event ="DOMActivate"> < label >Mute</ label > < action > < setvalue ref ="/settings/volume"> 0</ setvalue > < message >Muted</ message ></ action ></ trigger > </ group ></ body ></ html > XForms uses a relatively advanced CSS feature called pseudoclasses to enable the styling of form controls to reflect the state of the underlying data. We have seen the use of attribute class in many of the user interface examples in this book when creating CSS style rules to apply to a set of controls. CSS pseudoclasses can be thought of as creating an imaginary class attribute on elements, based on the state of the underlying document tree. Consider the creation of a CSS style rule that specifies how required fields should be presented to the user. Property required can have one of two possible boolean values. We use pseudo classes :required and :optional that correspond to these two values. We then specify the CSS style to be used for :required and :optional using the syntax defined in CSS3 for associating style rules with pseudo classes. When property readonly on an instance node becomes true , the XForms processor sets controls bound to this node to have pseudoclass :required ; similarly, when property required becomes false , controls bound to that node get pseudoclass :optional . The CSS-aware browser can then use this information to update the presentation. For the case of the specialized volume control described in Figure 5.1, we use CSS pseudoclass :out-of-range to attach a special style to be used when control We list the proposed CSS3 pseudoclasses with their corresponding XForms model properties in Table 5.1 and show an example of their use in Figure 5.2. Note that these pseudoclasses are being defined jointly by the CSS and XForms working groups and might be updated in the future. Figure 5.2 CSS style rules using pseudoclasses.< style xmlns:xf ="http://www.w3.org/2002/xforms"> @namespace xf url(http://www.w3.org/2002/xforms); /* Red background on all invalid form controls */ *:invalid {background-color:red; } /* Red asterisk after all required form controls */ *:required::after {content: "*"; color:red; } /* Do not render non-relevant form controls */ *:disabled {visibility: hidden; } /* Display non-relevant repeat items in the system GrayText color */ *::repeat-item:disabled { visibility: visible; color: GrayText;} </ style > Table 5.1. CSS3 Pseudoclasses and the Associated XForms Model Properties
5.2 Attaching Constraints Via Element |
| nodeset | Locates set of nodes to which a model property is to be applied. The specified property will be applied to each node in the node-set. |
| property | The name of the property to be applied. |
Model property bindings created via
bind
can be collected inside a container
bind
element for authoring convenience. When collected inside a
bind
container, this container can use XForms binding expressions to define the evaluation context for the binding expressions that appear within contained
bind
elements. We show a template
bind
in Figure 5.3.
bind
is used to attach model properties. < model xmlns ="http://www.w3.org/2002/xforms"> < instance > < root xmlns =""> < c1 >< c11 />< c12 /></ c1 > < c2 >< c21 />< c22 /></ c2 > </ root ></ instance > < bind nodeset ="/root"> < bind nodeset ="c1/c11" required ="value"/> < bind nodeset ="*" type ="xsd:string"/> </ bind ></ model >