The previous sections have described the various XForms user interface controls for collecting data from the user. Data collection apart, user interface controls are used to trigger specific actions. In traditional visual interfaces, such controls manifest themselves as buttons. Buttons in a visual interface are wired to an underlying action to be executed upon activation of the button. The visual rendering of the button is styled to indicate whether the underlying action is currently available to the user. A specific user action, for example, pressing the button, causes the underlying action to be triggered. XForms defines abstract control Element 3.7.1 Anatomy of Element |
ev:event | Attribute ev:event specifies the event type that triggers the encapsulated action. [7] The specified event type may be any one of the standard DOM2 event types; it may also be any of the special event types defined by the XForms specification, for example, xforms-reset . |
ev:handler | Attribute ev:handler specifies the action to be triggered upon receiving the desired event. |
Binding | Optional binding attributes can be used to enable or disable the trigger conditionally. |
| Child element |
[7] Here, namespace prefix ev is used to denote the XML Events namespace.
Figure 3.25 shows a fragment of a user interface consisting of multiple conceptual pages . Each group of controls is authored within a separate group
construct described in detail in the next chapter. Depending on the characteristics of the target device, each group might be displayed on a separate screen. The
trigger
shown here is used to move to the section in the user interface that collects personal information by invoking XForms action handler
setfocus
.
It achieves this by listening for event DOMActivate ”a generic event that might be raised when the user activates the control, for example, by clicking a mouse when using a visual interface. Action setfocus
specifies the control to move focus to the attribute control as shown in this example. Notice that action
setfocus
appears as a direct child of element
trigger
in this example. If there were multiple actions to be executed in response to the DOMActivate event, we would have used element
action
to group the various actions.
Notice further that attribute ev:event has been placed on element setfocus
, as opposed to placing it directly on element
trigger
. This usage is consistent with XML Events and affords the ability to create triggers that invoke different actions based on the received event as illustrated in Figure 3.26. The
trigger
shown in that example responds to two separate events, DOMActivate and xforms-focus . It invokes action
setfocus
upon receiving event DOMActivate , as in the earlier example. In addition, it has been set up to refresh the XForms user interface when this control receives focus. This is achieved by attaching a
refresh
action that responds to event xforms-focus .
< body xmlns:ev ="http://www.w3.org/2001/xml-events"> < trigger xmlns ="http://www.w3.org/2002/xforms" id ="getPersonal"> < label >Collect Personal Information</ label > < action ev:event ="DOMActivate"> < setfocus control ="personal"/> < refresh ev:event ="xforms-focus"/> </ action ></ trigger >... < group xmlns ="http://www.w3.org/2002/xforms" id ="personal"> < label >Personal Information</ label >...</ group > </ body >