The event() Function
Syntax
Copy Code | |
---|---|
object event(string) |
Description
Function event() returns context specific information determined by the string argument. The returned context information is an XPath object whose type and content depends upon the requested property. Each event describes what properties can be accessed by this function and the type and value that will be returned as the result.
The event context properties available for each event are provided in the sections that describe the events.
This function is intended for use in the XPath expressions of XForms actions. If invoked for any other XPath expression, such as a binding expression or model item property expression, this function returns the empty string. If this function is invoked from an XPath expression for an XForms action, then event context information is used from the most recently dispatched event whose action handler contains the XForms action.
Some properties defined for an event may be unavailable if certain prerequisite conditions were not met prior to the event being dispatched. If the event context information does not contain the property indicated by the string argument, then an empty node-set is returned.
Example
XML | Copy Code |
---|---|
<xforms:model> <xforms:instance> <Dates> <date xsi:type="xsd:date">2006-12-25</date> <date xsi:type="xsd:date">2006-01-01</date> </Dates> </xforms:instance> <xforms:action ev:event="xforms-insert"> <xforms:setvalue model="description_catcher" ref="insert_description" value="event('inserted-nodes')"/> </xforms:action> </xforms:model> <xforms:model id="description_catcher"> <xforms:instance> <descriptions> <insert_description/> </descriptions> </xforms:instance> </xforms:model> ... <xforms:group> <xforms:trigger> <xforms:label>Insert A Date</xforms:label> <xforms:action ev:event="DOMActivate"> <xforms:insert nodeset="/Dates/date" at="1" position="before"/> </xforms:action> </xforms:trigger> </xforms:group> <xforms:group> <xforms:output model="description_catcher" ref="insert_description"> <xforms:label></xforms:label> </xforms:output> </xforms:group> |
Within the above example, when the Insert A Date trigger is activated, the insert action inserts a copy of the last node from the specifed nodeset binding (the node with value "2006-01-01") into the default instance. This action triggers the xforms-insert event.
Within the model definition, there's an action (element) listening for the xforms-insert event, which uses the event() function within the nested setvalue action element to copy the inserted-nodes information (which is actually a node-set itself) into the insert_description node of the (default instance of the) description_catcher model.
So, after activating the trigger, the default instance of the default model contains a copy of the second node and the output will display "2006-01-01".
Specification
Link to the XForms specification: the event() function.