Standard support
Last updated
Last updated
The event model of XForms is based on the specification. This is the same specification that defines how your web browser handles events in HTML documents. This is good news because it means that his knowledge is reusable between XForms and HTML/JavaScript development!
What's new with XForms is that it allows users to declaratively register event handlers following the specification. If you write HTML and JavaScript code running directly in your browser, you would typically register event handlers using JavaScript APIs. In XForms, which does not mandate JavaScript, XML Events provide a declarative alternative to using JavaScript. This usually makes it clearer how listeners are attached to XForms objects.
ev:
prefix for event attributesThe usual XForms way of using XML events is by prefixing attributes with the ev:
prefix. This is in fact not absolutely mandated by XForms, and leads to heavier attribute syntax, so Orbeon Forms allows using the attributes without a namespace. The examples below usually use the ev:
prefix, but most of the Orbeon Forms code doesn't.
Example with prefix:
Example without prefix:
[TODO: basic placement and ev:event support]
[SINCE Orbeon Forms 2018.1]
Orbeon Forms now considers that non-relevant event handlers, that is handlers which are within non-relevant content, do not run. Previously, such handlers would run. For example the following <xf:message>
actions never run:
On the other hand, the following actions run:
For backward compatibility, if you need a non-relevant event handler to run, you can use the xxf:if-non-relevant="true"
attribute:
But please note that running event handlers in non-relevant contexts can be tricky. In particular, the XPath context might be empty, and XPath variables might be undefined.
The ev:observer
attribute allows you to register event handlers by specifying an element identifier, instead of embedding the event handler within that element. This is particularly useful to register event handlers on elements, which do not allow you to directly embed XML event handlers.
Note that you still need to use the ev:event
attribute to specify to what event the handler responds. The following example shows how you can define event handlers for XForms elements anywhere in an XForms document:
The above example also shows how you can constrain an event handler to respond to an event dispatched to a particular target element using the ev:target
attribute. Here, the event handler responds to DOMFocusIn
events, but only those dispatched to the my-input
control.
[TODO: describe]
[TODO: describe]
You can place event handlers at the top-level under the <xh:body>
element:
Previously, you had to use a top-level <xh:group>
for this to work:
You can also explicitly register top-level handlers using the #document
observer id:
NOTE: Events from top-level models do not bubble to handlers observing on #document
. Arguably, they should!
When using an XBL component, you can register handlers in the same way you register handlers on built-in XForms controls.
In this case, the handler is placed directly under the bound node (<fr:foo>
):
Event handlers with the ev:observer
attribute are also recognized as long as the handler is directly under the bound node:
NOTE: For event handlers nested further within the bound node, the behavior is up to the XBL component. Typically, components that are containing controls, such as <xf:input>
, manage event handlers as you expect!
Event handlers on XBL bindings are very similar to regular XML Events handlers, except:
they use the containing element placed within the
section of an XBL binding
attributes do not use the XML Events namespace (typically with the ev:
prefix)
the XBL 2 default-action
attribute is not supported but instead the XML Events 1 defaultAction
is supported (both support the value cancel
and perform
)
Example:
Orbeon Forms partially supports the XForms 1.1 delay
attribute on <xf:dispatch>
. The limitations are:
Events are not combined as specified in XForms 1.1.
Until Orbeon Forms 4.10 included:
A delay greater than zero always incurs a round-trip with the client. This may mean higher latency and resource usage than could be expected. You are advised to use delays in the order of seconds at least.
A delay of 0
causes the event to be dispatched synchronously right away, as if the delay
attribute is not present.
A non-integer value causes the action to fail with an error.
Since Orbeon Forms 2016.1:
Delayed events are checked for expiration before sending responses to the client.
A delay of 0
can be used to dispatch an event asynchronously with a guarantee that there will be no roundtrip to the client. This conforms to XForms 1.1.
A non-integer value causes the event to be dispatched synchronously right away. This conforms to XForms 1.1.
Event properties/context information of atomic types are now preserved and passed when the event is dispatched with a delay. Other types of event properties/context information (such as XML nodes) are not supported and will cause an error. The following types are supported:
xs:string
xs:boolean
xs:decimal
xs:integer
xs:double
xs:float
xs:dateTime
xs:date
xs:anyURI
: converted to a string representation
xs:duration
: converted to a string representation
xs:time
: converted to a string representation
The boolean attribute xxf:show-progress
allows specifying whether the client must enable the loading indicator when sending back delay events from the client. The default is true
and the indicator is used.
Not supported by Orbeon Forms.
Not supported by Orbeon Forms.
There are differences between some events specifications, in particular with regard to how events phases are defined hand how handlers can specify event phases.
DOM Level 3 Events nicely clarifies the different event phases (capture, target, and bubbling).
XML Events 1 phase="default"
attribute means a listener is activated on the target
or bubbling
phase.
XML Events 1 does not support activating an event strictly on the target
or bubbling phase.
XBL 2 adds a default action phase separate from the target
or bubbling
phases.
XBL 2 proposes capture
, target
, bubble
, default-action
, and unspecified values for the phase attribute. If unspecified, this means the target
or bubbling
phase.
XML Events 2 is a W3C Working Group Note and covers declarative event handling for XML
Custom event context information is not supported and simply ignored (see ).
[UP TO 4.10] The xxf:progress-message
attribute allows specifying a custom progress message when xxf:show-progress
is true
. By default, the standard progres message is used. [SINCE 2016.1] Orbeon Forms switched to using a instead of a loading indicator message, and as a result specifying a "progress message" does not make sense anymore. The xxf:progress-message
attribute is deprecated: specifying it has no effect, and might be considered as an error in future versions.
For more information, see the .