1 DOM value_of_target

Testing XForms dispatch

The XForms dispatch element is used by form authors to send events to other elements. The dispatch uses a target variable, a name variable, and a delay variable to send events. The target variable is the IDREF of an element that the event is going to be sent to. The name variable is the name of the event that is being sent. The delay variable is the amount of time that the dispatch must wait before it can send the event. These variables can be defined by attribute form or element form.

For each of the examples we have below, there is both the markup and a live version of the code; so click the buttons and check the outputs to see how the markup behaves.

The basic format

A simple example has a dispatch with target and name as attributes and no delay variable (which means the event is dispatched instantly):

		    <xf:group id="simple_example">
		      <xf:setvalue ev:event="DOM" ref="number" value="2"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to set the number to 2.</xf:label>
		      <xf:dispatch target="simple_example" name="DOM" ev:event="DOMActivate" ></xf:dispatch>
		    </xf:trigger>
		  
Click to set the number to 2. Number:

The name variable examples

The name variable can be defined by the name attribute:

		    <xf:group id="name_attribute">
		      <xf:setvalue ev:event="some name" ref="number" value="4"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to set the number to 4.</xf:label>
		      <xf:dispatch target="name_attribute" name="some name" ev:event="DOMActivate" ></xf:dispatch>
		    </xf:trigger>
		  
Click to set the number to 4. Number:

The name variable can be defined in the name element:

		    <xf:group id="name_element">
		      <xf:setvalue ev:event="DOM" ref="number" value="5"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to set the number to 5.</xf:label>
		      <xf:dispatch target="name_element" ev:event="DOMActivate" >
		      	<xf:name>DOM</xf:name>
		      </xf:dispatch>
		    </xf:trigger>
		  
Click to set the number to 5. DOM Number:

The name variable can be defined in the value attribute of the name element:

		    <xf:group id="value_of_name">
		      <xf:setvalue ev:event="DOM" ref="number" value="6"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to set the number to 6.</xf:label>
		      <xf:dispatch target="value_of_name" ev:event="DOMActivate" >
		      	<xf:name value="/data/name"></xf:name>
		      </xf:dispatch>
		    </xf:trigger>
		  
Click to set the number to 6. Number:

The target variable examples

The target variable can be defined by the target attribute:

		    <xf:group id="target_attribute">
		      <xf:setvalue ev:event="DOM" ref="number" value="14"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to set the number to 14.</xf:label>
		      <xf:dispatch target="target_attribute" name="DOM" ev:event="DOMActivate" ></xf:dispatch>
		    </xf:trigger>
		  
Click to set the number to 14. Number:

The target variable can be defined in the target element:

		    <xf:group id="target_element">
		      <xf:setvalue ev:event="DOM" ref="number" value="15"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to set the number to 15.</xf:label>
		      <xf:dispatch name="DOM ev:event="DOMActivate" >
		      	<xf:target>target_element</xf:target>
		      </xf:dispatch>
		    </xf:trigger>
		  
Click to set the number to 15. target_element Number:

The target variable can be defined in the value attribute of the target element:

		    <xf:group id="value_of_target">
		      <xf:setvalue ev:event="DOM" ref="number" value="16"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to set the number to 16.</xf:label>
		      <xf:dispatch name="DOM ev:event="DOMActivate" >
		      	<xf:target value="/data/target"></xf:target>
		      </xf:dispatch>
		    </xf:trigger>
		  
Click to set the number to 16. Number:

The delay variable examples

The delay variable can be defined in attribute form on the dispatch element:

		    <xf:group id="delay_attribute">
		      <xf:setvalue ev:event="DOM" ref="number" value="24"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to delay and set the number to 24.</xf:label>
		      <xf:dispatch target="delay_attribute" name="DOM" ev:event="DOMActivate" delay="3000"></xf:dispatch>
		    </xf:trigger>
		  
Click to delay and set the number to 24. Number:

The delay variable can be defined in the delay element:

		    <xf:group id="delay_element">
		      <xf:setvalue ev:event="DOM" ref="number" value="25"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to delay and set the number to 25.</xf:label>
		      <xf:dispatch target="delay_element" name="DOM" ev:event="DOMActivate" >
		      	<xf:delay>3000</xf:delay>
		      </xf:dispatch>
		    </xf:trigger>
		  
Click to delay and set the number to 25. 3000 Number:

The delay variable can be defined in the value attribute of the delay element:

		    <xf:group id="value_of_delay">
		      <xf:setvalue ev:event="DOM" ref="number" value="26"></xf:setvalue>
		    </xf:group>
		    <xf:trigger>
		      <xf:label>Click to delay and set the number to 26.</xf:label>
		      <xf:dispatch target="value_of_delay" name="DOM" ev:event="DOMActivate" >
		      	<xf:delay value="/data/time"></xf:delay>
		      </xf:dispatch>
		    </xf:trigger>
		  
Click to delay and set the number to 26. Number:

Further reading

For more information see the definition of dispatch in the XForms 1.1 specification.