Name

setvalue

Synopsis

Binding attributes on this element select the location in the instance data to receive the value, which is always simpleContent. Note that XForms doesn’t include a way to arbitrarily alter complexContent through XForms Actions, though the insert and delete actions can to a limited extent.

Another job commonly reserved for scripting is to set values in the form, as shown in the earlier example in this chapter. This action can set the value of an attribute node or an element’s text node, to either a fixed value or the result of evaluating XPath.

The value to place in the instance is either an XPath expression, contained in the value attribute, or literal text as the content of the element. If both should happen to be present, the evaluated XPath is used.

Clearing a value is the same as setting a zero-length string—in other words, neither a value attribute nor element content.

setvalue can be useful in several contexts, as shown here:

<!-- on initialize, set a value of "0" -->
<setvalue bind="frequency" ev:event="xforms-ready">0</setvalue>
...
<!-- on initialize, copy the billing address to the shipping address -->
<setvalue ref="Shipping/Addr" value="../Billing/Addr"
               ev:event="xforms-ready"/>
...
<!-- clear a value when an Insert happens -->
<setvalue bind="phone_num" ev:event="xforms-insert"/>

Get XForms Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.