< XForms

Motivation

You want to be able to perform various tasks at various part of the form execution.

Method

XForms is integrated with the W3C XML Event standard. This standard creates standard names for almost all of the common events used in the lifecycle of a form. The W3C has attempted to standardize these events and their event labels so that they can be used consistently across browsers from all vendors.

XML Event Types

The following is a listing of the XForms events. Some events are tied to individual forms controls such as input, select and textarea and some are tied to the model within the form.

XForms events
EventCancelBubblesTarget
Initialization Events
xforms-model-construct NY<model>
xforms-model-construct-done NY<model>
xforms-ready NY<model>
xforms-model-destruct NN<model>
Processing Events
xforms-rebuild YY<model>
xforms-recalculate YY<model>
xforms-revalidate YY<model>
xforms-refresh YY<model>
Interaction Events
xforms-previous YN<control>
xforms-next YN<control>
xforms-focus YN<control>
xforms-help YY<control>
xforms-hint YY<control>
xforms-reset YY<model>
xforms-submit YY<submission>
DOMActivate YY<control>
Notification Events
DOMFocusIn NY<control>
DOMFocusOut NY<control>
xforms-value-changed NY<control>
xforms-select NY<item>, <case> or <itemset>
xforms-deselect NY<item>, <case> or <itemset>
xforms-scroll-first NY<repeat>
xforms-scroll-last NY<repeat>
xforms-insert NY<instance>
xforms-delete NY<instance>
xforms-valid NY<control>
xforms-invalid NY<control>
xforms-in-range NY<control>
xforms-out-of-range NY<control>
xforms-readonly NY<control>
xforms-readwrite NY<control>
xforms-required NY<control>
xforms-optional NY<control>
xforms-enabled NY<control>
xforms-disabled NY<control>
xforms-submit-done NY<submission>
xforms-submit-error NY<submission>
Error Notifications
xforms-binding-exception NY<bind>
xforms-link-exception NY<model>
xforms-link-error NY<model>
xforms-compute-exception NY<model>

Displaying Events in a Log File

One of the best ways to learn about how events get fired is to write them to a log instance and display the log at the bottom of the form. You can do this logging while you are building and debugging your form.

Add the following instance to your model:

<xf:instance xmlns="" id="log">
    <events>
       <event>log initialized</event>
    </events>
</xf:instance>

Whenever you want to see an event, just add an action that appends an event to the end of the log:

<xf:action ev:event="xforms-deselect">
    <xf:insert nodeset="instance('log')/event" at="last()" position="after" />
    <xf:setvalue ref="instance('log')/event[last()]" value="'Tab One deselected'" />
</xf:action>

Note that the message must be inside a pair of single quotes inside of double quotes.

At the end of the form you can display the data from the log instance by enclosing the output within a repeat.

<div id="event-log">
   <xf:repeat nodeset="instance('log')/event" class="log">
      <xf:output ref="." />
   </xf:repeat>
</div>

You can also style the event log with the following

#event-log {
   color: DarkGray;
   background-color: Lavender;
}
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.