9 XForms Actions

All form controls defined in this specification have a set of common behaviors that encourage consistent authoring and look and feel for XForms-based applications. This consistency comes from attaching a common set of behaviors to the various form controls. In conjunction with the event binding mechanism provided by [XML Events], these handlers provide a flexible means for forms authors to specify event processing at appropriate points within the XForms user interface.

NOTE: This example is based on the XML Events specification [XML Events], which is proceeding independently from XForms, and thus might be slightly incorrect.

Example: Action Syntax
<xforms:button>
  <xforms:caption>Reset</xforms:caption>
  <xforms:resetInstance ev:event="xforms:activate"/>
</xforms:button>

This example recreates the behavior of the HTML reset button, which this specification does not define as an independent form control.

For each built-in XForms action, this chapter lists the following:

Name
Description of behavior
XML Representation
Sample usage

All elements defined in this chapter explicitly allow global attributes from the XML Events namespace, and apply the processing defined in that specification in section 2.3 [XML Events].

9.1 dispatch

This action explicitly dispatches an XForms Event to a specific element identified by the target attribute.

Example: XML Representation: <dispatch>
<dispatch
  name = xsd:NMTOKEN
  target = xsd:IDREF
  bubbles = xsd:boolean : true
  cancelable = xsd:boolean : true
/>

name = xsd:NMTOKEN - required name of the event\ to dispatch.
target = xsd:IDREF - required reference to the event target.
bubbles = xsd:boolean : true - boolean indicating if this event bubbles—as defined in DOM2 events.
cancelable = xsd:boolean : true - boolean indicating if this event is cancelable—as defined in DOM2 events.

For events defined in the XForms specification, attributes bubbles and cancelable have no effect, since these event properties are defined in chapter 11 Processing Model.

9.2 refresh

This action dispatches an xforms:refresh event.

Example: XML Representation: <refresh>
<refresh/>

9.3 recalculate

This action dispatches an xforms:recalculate event.

Example: XML Representation: <recalculate>
<recalculate/>

9.4 revalidate

This action dispatches an xforms:revalidate event.

Example: XML Representation: <revalidate>
<revalidate/>

9.5 setFocus

This action explicitly sets focus to the form control referenced by the idref attribute by dispatching an xforms:focus event. Note that this event is implicitly invoked to implement XForms accessibility features such as accessKey.

Example: XML Representation: <setFocus>
<setFocus
  idref = xsd:IDREF
/>

idref = xsd:IDREF - required reference to a form control

Setting focus to a repeating structure sets the focus to the member represented by the repeat cursor.

9.6 loadURI

This action performs an XLink traversal.

Example: XML Representation: <loadURI>
<loadURI
  (single node binding attributes)
  xlink:href = xsd:anyURI
  xlink:show = ("new" | "replace" | "embed" | "other" | "none")
/>

(single node binding attributes) - Selects the instance data node containing the URI.
xlink:href - optional URI to load.
xlink:show - optional link behavior specifier.

Either the single node binding attributes, pointing to a URI in the instance data, or the attribute xlink:href are required. If both are present, the action has no effect.

Possible values for attribute xlink:show have the following processing for the document (or portion of a document) reached by traversing the link:

new

The document is loaded into a new window (or other presentation context). Form processing in the original window continues.

replace

The document is loaded into the current window. Form processing is interrupted, exactly as if the user had manually requested navigating to a new document.

embed

The document is incorporated into the current window in an application-specific manner. Form processing continues.

other

The document is loaded in an application-specific manner. The application should look for other markup present in the link to determine the appropriate behavior.

none

The document is loaded in an application-specific manner. The application should not look for other markup present in the link to determine the appropriate behavior.

9.7 setValue

This action explicitly sets the value of the specified instance data node.

Example: XML Representation: <setValue>
<setValue
  (single node binding attributes)
  value = XPath expression
>
  <!-- literal value -->
</setValue>

(single node binding attributes) - Selects the instance data node where the value is to be stored.
value = XPath expression - XPath expression to evaluate, with the result stored in the selected instance data node.

The element content of setValue specifies the literal value to set; this is an alternative to specifying a computed value via attribute value. The following two examples contrast these approaches:

Example: setValue with Expression
<setValue bind="put-here" value="a/b/c"/>

This causes the string value at a/b/c in the instance data to be placed on the single node selected by the bind element with id="put-here".

Example: setValue with Literal
<setValue bind="put-here">literal string</setValue>

This causes the value "literal string" to be placed on the single node selected by the bind element with id="put-here".

If neither a value attribute nor text content are present, the effect is to set the value of the selected node to the empty string ("").

9.8 submitInstance

This action explicitly initiates submit processing by dispatching an xforms:submit event.

Example: XML Representation: <submitInstance>
<submitInstance
  submitInfo = xsd:IDREF
/>

id = xsd:ID - optional unique identifier.
submitInfo = xsd:IDREF - optional reference to a submitInfo element.

Note:

This XForms Action is a convenient way of expressing the following:

<dispatch target="mysubmitinfo" name="submitInstance"/>

9.9 resetInstance

This action explicitly initiates reset processing by dispatching an xforms:reset event.

Example: XML Representation: <resetInstance>
<resetInstance
  model = xsd:IDREF
/>

model = xsd:IDREF - Selection of instance data for reset,defined at 8.12.3 Nodeset Binding Attributes

9.10 setRepeatCursor

This action marks a specific item as current in a repeating sequence (within 10.3 Repeating Structures).

Example: XML Representation:Action <setRepeatCursor>
<setRepeatCursor
  repeat = xsd:IDREF
  cursor = XPath expression that evaluates to number
/>

repeat = xsd:IDREF - required reference to a repeat
cursor = XPath expression that evaluates to number - required 1-based offset into the sequence.

9.11 insert

This action copies nodes from the containing document into the instance data. Any nodes of type xsd:ID are not copied.

The rules for insert processing are as follows:

  1. A new node-set is created by evaluating the node-set binding attributes against the containing document child nodes of instance.

  2. The last node of this node-set is deep copied into the instance data, such that the inserted node appears immediately before or after (depending on the value of attribute position) the n-th node in the node-set returned by evaluating the node-set binding attributes against the instance data, where n represents the number returned from node-set index evaluation, below.

Note:

The XForms Action setValue can be used in conjunction with insert to provide specific initial values for the newly inserted nodes.

The rules for selecting a node-set index are as follows:

  1. The return value of the XPath expression in attribute at is processed according to the rules of the XPath function round(). For example, the literal 1.5 becomes 2, and the literal 'string' becomes NaN.

  2. If the result is NaN, the insert operation has no effect.

  3. If the result is not a valid index for the node-set, it is clipped to the either 1 or the size of the node-set, whichever is closer.

This action results in the insertion of model items to the XForms Model. These model items should be constructed by re-evaluating any necessary bindings and applying the XForms Constraints in scope for each node. When used with repeating structures 10.3 Repeating Structures, this causes the instantiation of the necessary user interface for populating a new entry in the underlying collection.

Example: XML Representation:Action <insert>
<insert
  (node-set binding attributes)
  at = XPath expression
  position = "before" | "after"
/>

(nodeset binding attributes) - Selection of instance data nodes, defined at 8.12.3 Nodeset Binding Attributes
at - required XPath expression evaluated to determine insert location.
position - required selector if insert before/after behavior.

An example of using insert with a repeating structure is located at 10.3 Repeating Structures.

9.12 delete

This action deletes nodes from the instance data.

The rules for delete processing are as follows:

  1. A node-set is produced by evaluating the node-set binding attributes against the instance data.

  2. The n-th node is deleted from the instance data, where n represents the number returned from node-set index evaluation, defined in 9.11 insert.

This action results in the deletion of model items to the XForms Model. These model items should be deleted by re-evaluating any bindings that refer to the nodes being deleted. When used with repeating structures, this causes the destruction of the necessary user interface for populating the entry at the current cursor position in the underlying collection.

Example: XML Representation:Action <delete>
<delete
  (node-set binding attributes)
  at = XPath expression
/>

(nodeset binding attributes) - Selection of instance data nodes, defined at 8.12.3 Nodeset Binding Attributes
at - XPath expression evaluated to determine insert location.

An example of using delete with a repeating structure is located at 10.3 Repeating Structures.

9.13 toggle

This action selects one possible choice from an exclusive list e.g., within 10.2 Conditional Constructs For Dynamic User Interfaces, by dispatching an xforms:toggle event.

Example: XML Representation: Action <toggle>
<toggle
  case = xsd:IDREF
/>

case = xsd:IDREF - required reference to a case section inside the conditional construct

The toggle action adjusts all selected attributes on the affected cases to reflect the new state.

9.14 script

This action executes script.

Example: XML Representation: Action <script>
<script
  type = xsd:string
>
  <!-- #CDATA -->
</script>

type = xsd:string - required mime-type identifier of scripting language used

9.15 message

This action encapsulates a message to be displayed to the user.

Example: XML Representation: <message>
<message
  (single node binding attributes)
  xlink:href = xsd:anyURI
  level = "ephemeral" | "modeless" | "modal"
>
  <!-- mixed content -->
</message>

(single node binding attributes) - optional attributes that point to the instance data for a string message.
xlink:href = xsd:anyURI - optional specifier of an external resource for the message.
level - required message level identifier.

The message specified can exist in instance data, in a remote document, or as inline text. If multiple captions are specified in this element, the order of preference is: ref, xlink:href, inline.

A graphical browser might render an ephemeral message as follows:

an average-looking text entry form control, with a mouse pointer visible and      a tooltip below, reading 'Please enter the number and street name'

A graphical browser might render a modeless message as follows:

a password entry form control, with a popup window below,                           displaying instructions for retrieving a forgotten password

A graphical browser might render a modal message as follows:

an alert popup , with a helpful error message.

9.16 action

This element can be used to bind XForms Actions to form controls and group them around a common event handler.

Example: XML Representation: <action>
<action
>
  <!-- Action handlers -->
</action>