<script> or <action>?[SINCE: 2011-04-07]
Two action names are available to run scripts: - <xxforms:script>:
- this is a custom Orbeon Forms action
- this never runs nested XForms actions
- without a
type attribute, the default is to run client-side JavaScript - with a
type attribute, this is able to run nested client-side JavaScript or server-side XPath scripts
- <xforms:action type="...">:
- this is a standard XForms action with an extension
type attribute - without a
type attribute, the behavior is standard XForms and runs nested XForms actions - with a
type attribute, this is able to run nested client-side JavaScript or server-side XPath scripts
As of 2011-04, Orbeon favors the use of <xforms:action type="...">. Client-side JavaScriptThe <xxforms:script> action allows you to call client-side JavaScript as a result of XForms events:
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref=".">test</xforms:setvalue>
<xxforms:script>var v = 2; myValueChanged(v);</xxforms:script>
</xforms:action>
Scripts run with <xxforms:script> have access to the following JavaScript variables: this: element observing the event causing <xxforms:script> to runevent:event.target: returns the element which is the target of the event causing <xxforms:script> to run
NOTE: <xxforms:script> actions are currently always executed last in a sequence of XForms actions, even if they appear before other XForms actions.
[SINCE: 2011-04-07]
You can also run client-side JavaScript with <xforms:action> by setting the type attribute to javascript:
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref=".">test</xforms:setvalue>
<xforms:action type="javascript">var v = 2; myValueChanged(v);</xxforms:script>
Server-side XPath scripts[SINCE: 2011-04-07]
Simple server-side scripts can be written in XPath. This is particularly useful when using extension functions that have side effects.
You specify an XPath script either with:
<xforms:action type="xpath">
or:
<xxforms:script type="xpath">
Example:
xxf:set-session-attribute('foo', $total),
xxf:set-session-attribute('bar', instance()/bar)
When putting multiple XPath statements, separate them with a comma. This creates an XPath sequence, which is evaluated in order.
XPath scripts have access to the current XPath context, including the focus and in-scope variables.
|