LCD Scripting with JavaScript
JavaScript and FormCalc expose the same object model.
The XML Forms Architecture (XFA) defines a complete Scripting Object Model (XFA-SOM).
Again, you can use the LCD built-in documentation on these topics, but even more powerful is the documentation found on the Adobe sites. Search for LiveCycle Designer XFA, LiveCycle Designer scripting reference, LCD scripting basics, or LCD XFA model, for example.
Keep in mind that scripting is optional and reduces the form's processing performance. If possible, all necessary coding (for example, to initialize values in forms) should happen in the print program (which is officially called the application program).
Of course, in interactive scenarios, you need to code scripting and react dynamically to the user's input. Think of validations, summing user-entered values, etc.
When scripting in XFA, the objects are referenced using XFA-SOM expressions. XFA-SOM has been defined in such a way that a simple reference can be used directly either in FormCalc or in JavaScript as the name of the object.
In JavaScript, addressing the value of the TEXTFIELD field in the above example could be done via TEXTFIELD.rawValue or this.rawValue. Adobe calls this a property of the TEXTFIELD object.
JavaScript does not automatically resolve object references into references to the object's value.
TEXTFIELD can be thought of a pointer to the TEXTFIELD object itself. This is in keeping with the object orientation of JavaScript.
FormCalc is value-oriented. If references are needed, the “ref()” function must be used to create a reference.
In FormCalc, dereferencing the reference to the object's value is done automatically (like *pointer in C language).
In JavaScript the “rawValue” property is needed to address the field value.
The JavaScript specification places certain restrictions on the syntax of object names. These restrictions mean that more sophisticated XFA-SOM expressions may not be usable as object names. In these cases, it is necessary to dereference an XFA-SOM expression by supplying it as a string to a method at runtime.
FormCalc can dereference most XFA-SOM expressions without an explicit method call; however, it too has limitations. For more information about these limitations, see Using SOM Expressions in FormCalc in the built-in manual and Using SOM Expressions in JavaScript, also inside the built-in manual.
Notice the use of the rawValue property in JavaScript. This property references the actual value of the field or object. The result of the arithmetical operation used in the example “lv_result = lv_text + lv_number;” is “1718”.If numbers should be added, you need to convert the string into a number first:“lv_result = parseFloat(lv_text) + lv_number;”
If global JavaScript variables are needed, create a SCRIPT OBJECT:
The following are some ways to trace or “debug” scripting inside forms: