XFA Specification
Chapter 3, Object Models in XFA
Scripting Object Model
98
Example 3.5
Dot and dash in name are mis-interpreted
<calculate>
<script contentType="application/x-javascript">
// ’.’ interpreted as object separator and ’-’ as subtraction
xfa.form.subform.My.childs-toy
</script>
</calculate>
Using SOM Expressions in FormCalc
For each script in a template, the script language is encoded in the script element by the contentType
attribute. If this attribute is not specified the language defaults to application/x-formcalc, which signifies
FormCalc.
SOM expressions are native to FormCalc. Hence, any valid SOM expression can be used anywhere
FormCalc requires you to specify a DOM node.
The FormCalc scripting language is, in general, oriented to strings rather than objects. It does not store all
variables internally as strings, but it does try to store data in forms that can be converted to and from
strings. In keeping with this, when it encounters a SOM expression for a node it looks for a property of that
node called value. If the property exists, it takes the string value of that property as the resolved value for
the SOM expression. Thus for example, given the data for the receipt example, the FormCalc expression
$data.Receipt.Detail[1].Units
yields not the Units node but rather its value, which is 5. Similarly the expression
sum($data.Receipt.Detail.Total_Price[*])
specifies a list of field nodes, but when the
sum()
function processes each node in the list it looks up the
value property of the node and adds together these numbers.
Runtime resolution of object names
Sometimes you may want to build the name of an object in a string at run time. You can use the
resolveNode()
method of
$form
to translate the string into an object reference. For example,
$form.resolveNode(My_String)
There is also a
resolveNodes()
method that returns a list of zero or more object references. For
example:
sum($form.resolveNodes(My_String))
All nodes in all XFA DOMs have
resolveNode()
and
resolveNodes()
methods. Furthermore, for the
types of SOM expressions described under
“Basic Object References” on page 85,
the
resolveNode()
or
resolveNodes()
method of any node can be used. However for the advanced expressions described in
“Relative References” on page 100
you must use the methods of the
$form
object or the $ object. It is
recommended to use
$form
at all times to reduce the chance of error.
Using SOM Expressions in ECMAScript
For each script in a template, the script language is encoded in the script element by the contentType
attribute. If this attribute is specified as application/x-ecmascript it signifies that the language is
ECMAScript. ECMAscript was formerly known as JavaScript.
Home Index Bookmark Pages
Pages: Home Index All Pages