LiveCycle Designer Scripting Basics
LiveCycle Designer Scripting Basics
LiveCycle Designer Scripting Basics
2007 Adobe Systems Incorporated. All rights reserved. Adobe LiveCycle Designer ES 8.1 Scripting Basics for Microsoft Windows Edition 1.1, July, 2007 If this guide is distributed with software that includes an end user agreement, this guide, as well as the software described in it, is furnished under license and may be used or copied only in accordance with the terms of such license. Except as permitted by any such license, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe Systems Incorporated. Please note that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end user license agreement. The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in the informational content contained in this guide. Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law. The unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please be sure to obtain any permission required from the copyright owner. Any references to company names, company logos and user names in sample material or sample forms included in this documentation and/or software are for demonstration purposes only and are not intended to refer to any actual organization or persons. Adobe, Adobe logo, Acrobat, LiveCycle, Minion, Myriad, and Reader are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. JavaScript is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries. Microsoft and Windows are either trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. This product contains either BISAFE and/or TIPEM software by RSA Data Security, Inc. This product includes software developed by the Apache Software Foundation (http://www.apache.org/). This product includes code licensed from RSA Data Security. This product includes software developed by the JDOM Project (http://www.jdom.org/). Macromedia Flash 8 video is powered by On2 TrueMotion video technology. 1992-2005 On2 Technologies, Inc. All Rights Reserved. http://www.on2.com. This product includes software developed by the OpenSymphony Group (http://www.opensymphony.com/). Portions of this code are licensed from Nellymoser(www.nellymoser.com). MPEG Layer-3 audio compression technology licensed by Fraunhofer IIS and THOMSON Multimedia (http://www.iis.fhg.de/amm/). This product includes software developed by L2FProd.com (http://www.L2FProd.com/). The JBoss library is licensed under the GNU Library General Public LIcense, a copy of which is included with this software. The BeanShell library is licensed under the GNU Library General Public License, a copy of which is included with this software. This product includes software developed by The Werken Company (http://jaxen.werken.com/). This product includes software developed by the IronSmith Project (http://www.ironsmith.org/). The OpenOffice.org library is licensed under the GNU Library General Public License, a copy of which is included with this software. This product includes software developed by Gargoyle Software Inc. (http://www.GargoyleSoftware.com/). Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA. Notice to U.S. Government End Users. The Software and Documentation are Commercial Items, as that term is defined at 48 C.F.R. 2.101, consisting of Commercial Computer Software and Commercial Computer Software Documentation, as such terms are used in 48 C.F.R. 12.212 or 48 C.F.R. 227.7202, as applicable. Consistent with 48 C.F.R. 12.212 or 48 C.F.R. 227.7202-1 through 227.7202-4, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as Commercial Items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions herein. Unpublished-rights reserved under the copyright laws of the United States. Adobe Systems Incorporated, 345 Park Avenue, San Jose, CA 95110-2704, USA. For U.S. Government End Users, Adobe agrees to comply with all applicable equal opportunity laws including, if appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance Act of 1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1 through 60-60, 60-250, and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be incorporated by reference.
Contents
About This Document.................................................................................................................. 6
Who should read this document? ............................................................................................................................................ 6 Purpose and scope ........................................................................................................................................................................ 6 Additional information................................................................................................................................................................. 7
Events ......................................................................................................................................... 26
About events..................................................................................................................................................................................26 Types of events .............................................................................................................................................................................26 Process events ...............................................................................................................................................................................26 Interactive events.........................................................................................................................................................................27 Application events .......................................................................................................................................................................29 List of events ..................................................................................................................................................................................30 calculate event........................................................................................................................................................................30 change event...........................................................................................................................................................................31 click event .................................................................................................................................................................................32 docClose event .......................................................................................................................................................................32 docReady event ......................................................................................................................................................................33 enter event ...............................................................................................................................................................................33
3
Contents
4
exit event ..................................................................................................................................................................................34 form:ready event....................................................................................................................................................................34 full event....................................................................................................................................................................................35 indexChange event ...............................................................................................................................................................35 initialize event .........................................................................................................................................................................36 layout:ready event.................................................................................................................................................................36 mouseDown event ................................................................................................................................................................37 mouseEnter event..................................................................................................................................................................37 mouseExit event.....................................................................................................................................................................38 mouseUp event ......................................................................................................................................................................38 postPrint event .......................................................................................................................................................................39 postSave event........................................................................................................................................................................39 preOpen event........................................................................................................................................................................40 prePrint event..........................................................................................................................................................................40 preSave event..........................................................................................................................................................................41 preSubmit event.....................................................................................................................................................................41 validate event..........................................................................................................................................................................42
Scripting Languages.................................................................................................................. 43
Differences between FormCalc and JavaScript functions.............................................................................................43 Using FormCalc .............................................................................................................................................................................49 About using FormCalc..........................................................................................................................................................49 Using built-in functions .......................................................................................................................................................49 To attach a FormCalc function to an object .................................................................................................................50 Built-in function syntax........................................................................................................................................................50 Creating basic calculations.................................................................................................................................................51 Using JavaScript............................................................................................................................................................................53 About using JavaScript ........................................................................................................................................................53 Creating scripts using JavaScript......................................................................................................................................53 To attach a JavaScript script to an object......................................................................................................................54
Variables..................................................................................................................................... 55
About variables .............................................................................................................................................................................55 Naming variables..........................................................................................................................................................................55 To define a text variable.............................................................................................................................................................55 To view a text variable definition ...........................................................................................................................................56 To delete a text variable.............................................................................................................................................................56 Using variables in calculations and scripts..........................................................................................................................56
Contents
5
About script fragments ..............................................................................................................................................................69 Script fragment properties .......................................................................................................................................................69 To create a script fragment.......................................................................................................................................................69 To insert a script fragment ........................................................................................................................................................70
15 Index .........................................................................................................................................121
Change the behavior and appearance of objects at run time Control the presentation of field values Provide interaction with form fillers using dialog boxes and visual cues Automate form filling Control the hosting environment Interact with web services Interacting with databases and populate forms with data from data sources
Here you will find detailed information and examples of what the LiveCycle Designer ES calculation and scripting capabilities are and how to access them, as well as descriptions of the usage of the LiveCycle Designer ES Script Editor. LiveCycle Designer ES calculations and scripts are a powerful way to enhance and extend your LiveCycle Designer ES forms.
An introduction to using LiveCycle Designer ES calculations and scripts to extend your forms Easily understood, detailed information and examples of the LiveCycle Designer ES calculation and scripting features References to other resources where you can learn more about LiveCycle Designer ES scripting and related technologies
After reading this guide, you should be equipped to start using LiveCycle Designer ES calculations and scripts. During the development process, you will find that the descriptions and examples in this guide will provide you with enough direction and background to enable you to successfully complete your projects.
Additional information
Adobe has a wide variety of resources dedicated to LiveCycle Designer ES scripting focused at both the form author and the form developer audiences. The following illustration and section outline the different resources available and where to find them.
Roadmap
The roadmap document is the starting point for learning about the scripting resources available to you. Follow the paths and discover the different sources of scripting information and how they can help you meet your scripting needs.
User Forums
The LiveCycle Designer Forum is a meeting place for professionals who are interested in discussing issues related to LiveCycle Designer ES. Respond to reader questions, report bugs or issues with the product, or post questions of your own to other form designers and Adobe experts. For information, see www.adobeforums.com.
Scripting samples
The scripting samples are working forms or packages that include instructions on how the sample was created and any sample data used to create and view the form. New samples are added on an ongoing basis by both Adobe experts and third-party organizations. See the samples at www.adobe.com/devnet/livecycle/samples.html.
At a more advanced level, you can create your own functions tailored towards your own custom form processing needs. LiveCycle Designer ES supports two scripting languages, each geared towards the needs of a particular type of form developer. FormCalc is a straightforward, easy-to-use calculation language that is modelled on common spreadsheet functionality. It includes a variety of built-in functions designed to reduce the amount of time you need to spend developing your form design. JavaScript, a powerful scripting language, provides you with a great deal of flexibility when creating your scripts and allows you to leverage any existing knowledge of the language. Remember that scripting on a form is entirely optional. You can choose to take advantage of scripting to provide a richer user experience, but many of the most powerful features available during form creation are available in LiveCycle Designer ES without the use of scripts. However, through scripting, you can manipulate and control almost all aspects of your form design.
Scripts associated with a particular event execute whenever that event occurs. Some events can occur multiple times within the same form filling session. For example, the following script adds one to the current value of a numeric field:
NumericField1.rawValue = NumericField1.rawValue + 1;
If you add this script to the calculate event for NumericField1, when you open the form for the first time, NumericField1 displays the value 2. This indicates that the calculate event occurred twice in the sequence of events that occurred when the form was opened.
Reference syntax
Functions button
Show Lists all form design events that support user-defined scripting. Any events that do not apply to a particular object appear dimmed. Events that contain a calculation or script display an asterisk (*) beside the name of the event. Show Events for Child Objects Displays the event you have currently selected in the Show list for the current object and all of its child objects. If you select the uppermost object in the Hierarchy palette, this option displays the event you have currently selected in the Show list for all objects on your form. Functions Displays a list of available built-in FormCalc or JavaScript functions, depending on the scripting language you currently have selected in the Language list. To place a function onto your script editing field, select a function from the list and press Enter. Check Script Syntax Checks all of the scripts in a form for correct syntax and reports any errors on the Log tab in the Report palette.
11
Language Specifies the scripting language you want to use for the current calculation or script. Two options are available:
FormCalc is a native Adobe calculation language typically used for shorter scripts, such as simple calculations. JavaScript is a robust and flexible scripting language suitable for more complex scripts.
Run At Specifies where the calculation or script will execute. Three options are available:
Client Calculations and scripts execute while the client application (for example, Acrobat, Adobe Reader, or a web browser) processes the form. Server Calculations and scripts execute while the server application (for example, LiveCycle Forms ES) processes the form. Client and server Calculations and scripts execute while the server application (for example, LiveCycle Forms ES) processes the form, except in cases where the HTML client application supports client-side scripting. For example, a script that accesses a database to prefill data on a form.
Note: You can use the Expand button to quickly dock or undock the Script Editor when it is displayed in the LiveCycle Designer ES workspace.
Note: Multiline view adds the All Events and Events with Scripts options to the Show list. The All Events option displays all of the events for a particular form design object, even if the events do not contain any calculations or scripts. The Events with Scripts option displays only those events of a particular object that contain calculations or scripts.
3. Click the Defaults tab. 4. Select your default scripting language from the Default Language list. 5. Make a backup of the original form template file located in the Templates folder where LiveCycle Designer ES is installed. 6. Save the new form design as a TDS file and overwrite the corresponding form template. For example, save the file as Letter.tds and overwrite the Letter.tds file located in Templates\Blank folder.
1. Create a new form design. 2. Select File > Form Properties. 3. Click the Defaults tab. 4. Select your default processing application from the Default Run At list. 5. Make a backup of the original form template file located in the Templates folder where LiveCycle Designer ES is installed. 6. Save the new form design as a TDS file and overwrite the corresponding form template. For example, save the file as Letter.tds and overwrite the Letter.tds file located in Templates\Blank folder.
FormCalc Syntax Formatting to set the font in the Script Editor when you use FormCalc JavaScript Syntax Formatting to set the font in the Script Editor when you use JavaScript XML Source Syntax Formatting to set the font in the XML Source tab
3. In the Font box, select a font that supports your language. For example, Adobe Arabic supports Arabic, Adobe Hebrew supports Hebrew, Adobe Thai supports Thai, and Myriad Pro and Minion Pro support Vietnamese. You can locate the font you need for your language on the Internet if it is not already on your system. 4. Click OK. 5. Click OK to close the Options dialog box.
Purpose You can use the Hierarchy palette to determine the location of a form object for a reference syntax. The Hierarchy palette is a graphical representation of the structure of a form. It displays the contents of the Master Pages and Design View tabs. The Hierarchy palette also displays referenced objects under the Referenced Objects node. A referenced object is an object that is added to a form only when it is required. Whenever data flows across multiple pages or content areas, the overflow leader and trailer subforms are inserted into the form in the appropriate places.
Every LiveCycle Designer ES object that can be bound to a data source includes a Binding tab in the Object palette. If you bind an object on your form design to a particular data node from your data connection, the Default Binding (Open, Save, Submit) list displays a valid FormCalc reference syntax for accessing that data node. You can use the FormCalc reference syntax in other calculations or scripts for testing purposes. The XML Source tab contains the form designs XML code. The XML source code defines all aspects of the form. You can use the XML Source tab to view the XML Form Object Model structure of a form design and to understand the relationships between objects and properties. In the XML source, the XML element names are equivalent to the object names in the XML Form Object Model, and attributes are equivalent to properties. When you select an object in the Hierarchy palette and then click the XML Source tab, the first line of the corresponding element is highlighted. The object name in LiveCycle Designer ES, as listed in the Hierarchy palette, becomes the value of the name attribute in the XML source. You can set options in the Tools > Options dialog box for viewing the source in the XML Source tab, such as showing or hiding line numbers and setting the syntax coloring. Caution: It is recommended that you do not edit the XML source code directly.
You may also find it useful to change the default options for the Script Editor to make it easier to debug your calculations and scripts. These options are in the Workspace panel of the Options dialog box, which is available by selecting Tools > Options and then selecting Workspace from the list on the left. For example, you can choose to display line numbers in the Script Editor or change the formatting of FormCalc or JavaScript syntax.
More complex forms can take advantage of scripting to perform data source connectivity and data manipulation at run time. For examples of common scripting tasks, see Examples of Common Scripting Tasks on page 93. Creating calculations and scripts in LiveCycle Designer ES involves following a general process each time you attach a calculation or script to an object. Although not all aspects of the process are required each time you create a calculation or script, following the process helps to eliminate potential errors and unexpected results. In general, each time you create a calculation or script, you perform the following tasks:
Select the object to which you want to attach a calculation or script. Although you can create calculations and scripts that manipulate almost any object on your form design, not all form design objects support form events. For a list of standard objects included in the Object Library palette in LiveCycle Designer ES that support scripting, see Objects that support calculations and scripts on page 10. Select the form event to which you want to assign the calculation or script. The calculation or script associated with an event executes each time the form event triggers. For example, calculations or scripts attached to the click event of a button trigger each time the form filler clicks the button while filling the form. Choose the scripting language you want to use. Depending on the form you create, you may decide to use only FormCalc, only JavaScript, or a mixture of both languages. You can only use one scripting language on a particular instance of a form object event. Choose where the calculation or script runs, either on the client application, such as Acrobat or Adobe Reader, or on the server using LiveCycle Forms ES. Write your calculation or script in the script editing field of the Script Editor. Test the calculation or script either by using the Preview PDF tab or in your test environment.
16
For example, if you create a new text field named x within a subform object named Subform1, you access the text field object using the following syntax:
Subform1.x.[expression]
However, subform objects already have an XML Form Object Model property named x that represents the horizontal position of the subform on the form design. To avoid naming conflicts, you need to choose field naming conventions that differ from the XML Form Object Model naming conventions. For example, you can use any of the following field names for the text field in the example above:
For more information and a list of the XML Form Object Model property, method, and object names, see LiveCycle Designer ES Scripting Reference at http://www.adobe.com/do/learn_lc_scriptingReference.
FormCalc Built-in URL functions for Post, Put, and Get allow web-based interactions Compatible on all LiveCycle Designer ES and LiveCycle Forms ES supported platforms
JavaScript Create custom functions for your own specific needs Compatible on all LiveCycle Designer ES and LiveCycle Forms ES supported platforms
6. After you complete your form design, test and debug your calculations and scripts before putting them into production. For example, for the new button object, preview the PDF of the form using the Preview PDF tab. Click the button object to display the message box specified in step 5. For more information about the LiveCycle Designer ES objects that support scripting, see Objects that support calculations and scripts on page 10.
property name correctly and that the object is within the scope of the object where you are creating your script. For more information about referencing objects in calculations and scripts, see Referencing Objects in Calculations and Scripts on page 58. 1. Type the name of a form design object, property, or a valid FormCalc shortcut, followed by a period.
2. Select the method or property you want to apply for the form design object and continue writing the script. To close the statement completion list without selecting a function, press the Esc key. The list of available XML Form Object Model properties changes depending on the form design object or property that appears before the period. Note: The statement completion list appears only when accessing objects, properties, and methods in the XML Form Object Model. It does not appear when working with standard JavaScript objects or methods.
retrieves a value from a field may have different results if run before instead of after a form filler performs certain actions. For more information about events, see Events on page 26. Depending on the type of form you are creating, some events may never occur. For example, if you are creating a form that has a fixed layout and no interactive objects, then interactive events associated with form filler actions may never occur and, as a result, any scripts associated with those events will not run. Although LiveCycle Designer ES includes support for a wide variety of form events, it is possible to accomplish a wide variety of common calculation and scripting tasks by using only a few events that occur at major changes in a forms state, such as the following events:
docReady Initiates immediately after the form opens in Acrobat or Adobe Reader and immediately before the form filler can begin interacting with form objects. This event is the last event to occur before control of the form is given to the form filler. enter Initiates when the form filler changes the focus to a particular field, button, or subform. exit Initiates when the form filler changes the focus from a particular field, button, or subform, to another object. change Initiates when a form filler makes a change to a field value. This event is most commonly used with drop-down lists or list boxes to execute a script when a form filler makes a change to the current value. click Initiates when a form filler clicks a field or button. This event is most commonly used with buttons to execute a script when a form filler clicks the button.
If the Script Editor is not displayed on the screen, select Window > Script Editor. If the Script Editor is not large enough to display more than one line of script at a time, drag its lower line down to increase its size.
1. Select an object in your form. 2. In the Show list, select a valid scripting event.
To view a scripting event for a container object and its children in the Script Editor
1. If it is not already in multiline mode, expand the Script Editor to display multiple lines of script and ensure that the Show Events for Child Objects option is selected. 2. Select a container object, such as a subform. 3. In the Show list, select a valid scripting event. The events appear in the script editing field of the Script Editor, separated by the reference syntax for each event. Note that certain events only apply to specific types of objects. When you select a script event, the script editing field of the Script Editor only displays valid instances of the event. For example, if you select a subform that contains a drop-down list and select the preOpen event, the Script editor displays a single
entry representing the drop-down list. This is because the preOpen event only applies to drop-down lists. Alternatively, selecting the enter event displays two entries, one for the drop-down list and one for the subform. Note: The Show list denotes events that contain scripts using a trailing asterisk (*) after the name of the event. If an event contains a script, when you select the event from the Show list, the source appears in the script editing field of the Script Editor.
To view all scripting events for a single object in the Script Editor
1. Select an object in your form. 2. In the Show list, select All Events. The events appear in the script editing field of the Script Editor, separated by the reference syntax for each event.
To view all scripting events for a container object and its children in the Script Editor
1. If it is not already in multiline mode, expand the Script Editor to display multiple lines of script and ensure the Show Events for Child Objects option is selected. 2. Select a container object, such as a subform. 3. In the Show list, select All Events. The events appear in the script editing field of the Script Editor, separated by the reference syntax for each event.
To view all scripts for a single object in the Script Editor
1. Select an object that has scripts attached. 2. In the Show list, select Events With Scripts. The scripts appear in the script editing field of the Script Editor, separated by the reference syntax for each event.
To view all scripts for a container object and its children in the Script Editor
1. If it is not already in multiline mode, expand the Script Editor to display multiple lines of script and ensure that the Show Events for Child Objects option is selected. 2. Select a container object, such as a subform. All events for the container object and any child objects appear in the Script Editor. 3. In the Show list, select All Events. The scripts appear in the script editing field of the Script Editor, separated by the reference syntax for each event.
Using the LiveCycle Designer ES workspace palettes. For more information, see Using the workspace to debug calculations and scripts on page 14. For JavaScript only, using the JavaScript Debugger to assist you in testing your scripts. For more information about using the debugger, see To enable the JavaScript Debugger for LiveCycle Designer ES on page 72. Using the host model and event model properties and methods to troubleshoot your form.
The host model and event model provide functionality that lets you interact with either the host application or the various form events. These models are useful for returning information that can assist you in debugging calculation and scripts. For example, the following script returns a message at run time indicating the name of the event on which the script is placed. This indicates that a particular event has fired:
xfa.host.messageBox(xfa.event.name) // FormCalc xfa.host.messageBox(xfa.event.name); // JavaScript
Another example of using the host model and event model methods is to obtain the value of a field on an interactive form before a user manually changed it. This is useful for observing how the objects on your form design respond to user-entered data:
xfa.host.messageBox(xfa.event.prevText) // FormCalc xfa.host.messageBox(xfa.event.prevText); // JavaScript
To clone the sourceSet model, you need to change the line that accesses it by appending the clone (1) method to the end of the statement:
var oDB = xfa.sourceSet.nodes.item(nIndex).clone(1);
Tip: You can store the cloned data connection node in a variable or a variable defined in a script object.
Events
About events
Every calculation or script you attach to a form object is associated with a specific event. An event is defined as a particular occurrence or action that can change the state of a form and, when the change of state occurs, automatically invoke a calculation or script associated with the event. Events occur at various times, from the beginning of the form rendering process when merging data with a form design, all the way through to a form filler interacting with objects on a form in a client application. By applying calculations and scripts to specific events, you can control every aspect of how you present form objects, as well as form data, and how the objects and data respond to form filler interaction. A single change of state or form filler action may trigger multiple events. For example, tabbing from the current field to the next field triggers both the exit event for the current field and the enter event for the next field. If the current and next fields are in different subforms, a total of four events are triggered; namely, exit events for the current field and subform, and enter events for the next field and subform. In general, each of the different categories of form events follow a predictable ordering.
Types of events
Form events fall into one of the following categories: Process events This type of event initiates automatically as the result of an internal process or action related to objects on a form. For example, if a form filler clicks a button that adds a new page to the form, the initialize, calculate, validate, and layout:ready process events initiate automatically for the new page. Interactive events This type of event initiates as a direct result of form filler actions. For example, if a form filler moves the pointer over a field on a form, the mouseEnter event initiates in response to the action. Application events This type of event initiates as a result of the actions that either a client application or a server application performs. For example, you can create a calculation or script to perform a task immediately after the form is saved by using the postPrint event.
Process events
Process events initiate automatically as the result of an internal process or action related to a form or objects on a form. These events initiate immediately following significant form changes; for example, after a form design is merged with data or after the form pagination process finishes. Process events also initiate immediately after interactive events initiate. For example, immediately after any interactive event initiates, the calculate event initiates followed by the validate event. The following list contains the process events, which are available from the Show list in the Script Editor:
26
Events
Interactive events 27
Process events can initiate many times as a result of dependencies; that is, actions associated with a single event that ultimately initiates one or more additional events. Using an example of a form filler clicking a button to reveal a previously hidden portion of the form, after the form filler clicks the button, not only does a series of interactive and processing events initiate for the button itself, but a number of process events for the new subform initiates as well. The following image represents the general flow of events leading up to a PDF form opening in Acrobat or Adobe Reader.
After the form opens in Acrobat or Adobe Reader, these process events may still initiate as the result of changes made to the form. For example, the calculate, validate, and layout:ready events for an object initiate immediately after some interactive events occur; therefore, calculations and scripts attached to the processing events will run multiple times.
Interactive events
Interactive events initiate as a direct result of form filler actions, which makes these events useful for a variety of calculation and scripting tasks. For example, you can add a script to the mouseEnter event for a text field that changes the border color of the field to blue and a script to the mouseExit event that changes the border color back to the original color. This action creates a highlighting effect when form fillers move the pointer over the field to visually assist them while filling the form. Interactive events are also useful for changing form data in response to a form filler selection. For example, you can add a script to the change event for a drop-down list that updates the data values in multiple fields in response to the value the form filler selects in the drop-down list.
Events
Interactive events 28
The following list contains the interactive events, which are available from the Show list in the Script Editor:
The following image displays the general flow of events for form fillers who use the mouse to select an object and change its value. Note: This image provides a general flow of events; however, certain form filler actions and form objects can cause alternate event ordering. For example, if a form filler selects a value from a drop-down list, the mouseExit event occur after the click event but before the change or full events. Similarly, if a form filler selects a field, holds down the mouse, and then exits the field while still holding down the mouse button, the mouseUp event occurs out of the order described in this image.
Events
Application events 29
The following image displays the general flow of events for form fillers who use the keyboard to select an object and change its value.
Application events
Application events initiate as a result of the actions that either a client application or a server application performs, either in response to a form filler action or as a result of an automated process. For example, if a form filler saves the form in Acrobat or Adobe Reader, the preSave event initiates immediately before the save operation, followed by the calculate, validate, and layout:ready events, in order, for all objects on the form. The same event sequence initiates if the form contains a script that programmatically saves the form. The following list contains the processing events, which are available from the Show list in the Script Editor:
Application events do not exist as part of a general flow of events. They are single events corresponding to actions that the client or server application performs.
Events
List of events 30
List of events
calculate event
Description
Initiates in the following situations:
When your form design and data merge into your finished form. When a change occurs to any value that the calculation is dependent on, such as the value of a particular field, unless the form filler has manually overridden the calculated value. As a result, the object will display the return value of the event. The properties for manually overridden fields are located in the Value tab of the Object palette. When a field loses focus; for example, when a form filler clicks or uses the Tab key to exit a field.
When using the calculate event to perform calculations or scripts, consider the following potential issues:
Calculations and scripts on the calculate event must not make any changes to the structure of the form, except for the form field and data values. Content inserted by the calculate event must conform to the associated validations for the object; otherwise, validation errors will occur. Calculations and scripts must not include an infinite loop because it causes the form to update the value continuously. For example, a script that increments the value of a field as part of a looping expression, such as a while or for loop, could create an infinite loop. The last expression evaluated in the calculate event is used to populate the value of the current form object. For example, if the script on the calculate event first sets the value of the current field to 500 and then sets the value of another field to 1000, both fields will display the value 1000 at run time. As a result, you need to limit the scripting that you add to the calculate event to those that deal specifically with setting the value of the current field.
Type
Processing event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
Use the calculate event for updating numeric values in fields because this event initiates immediately after most other events. For example, on a purchase order form, you can use the calculate event for a field to determine the percentage of sales tax due based on the cost of the order. The calculation will initiate every time a change is made to the values in the form fields, ensuring that the value displayed for the sales tax is always correct.
Events
change event 31
However, because the calculate event can initiate many times, you must ensure that the calculation or script you add to the event will not cause data values to increment unnecessarily. For example, if your sales tax calculation adds the value of the sales tax to the total cost each time the calculate event initiates, the resulting total cost value on your form may be too large. For a detailed example of using the calculate event, see Calculating the field sums on page 106.
change event
Description
Initiates when a form filler changes the content of a field by performing one of these actions:
Types a keystroke providing the field has keyboard focus Pastes data into the field Makes a selection from a list box or drop-down list Selects or deselects a check box Changes the setting of a group of radio buttons
This event does not initiate in response to changes in the object values as a result of calculations or scripts, or by the merging of the form design with data.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
Use this event for any calculations or scripts that must initiate in response to a form filler changing the value of a field. For example, you can use the change event for a drop-down list to highlight specific rows in a table. Using this technique, each time the form filler selects a value in the drop-down list, the corresponding row of the table appears highlighted. For a detailed example of using the change event, see Getting the current or previous value of a drop-down list on page 103.
Events
click event 32
click event
Description
Initiates when a mouse click occurs within the region. When a click event initiates for a text or numeric field, calculations or scripts execute immediately. However, the value of the field does not change in response to calculations and scripts until the field loses focus. Note: You cannot place a calculation or script on the click event of a submit button because the calculation or script will override the submission action. Instead, place any calculations and scripts on the preSubmit event for a submit button. For more information about form submission actions, see the LiveCycle Designer ES Help.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
Use this event for performing an action as a direct response to a form filler clicking a button or selecting a radio button or check box on a form. For example, you can use the click event for a check box to hide and show a field on the form. For a detailed example of using the click event, see Changing the visual properties of an object on the client on page 100.
docClose event
Description
Initiates at the very end of processing a form, only if all form validations complete with no errors.
Type
Application event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
This event initiates too late to modify a saved form and is intended to provide the ability to generate an exit status or completion message. For example, you can use the docClose event to display a message to a form filler indicating that the form is completed.
Events
docReady event 33
docReady event
Description
Initiates immediately after the form opens in Acrobat or Adobe Reader.
Type
Application event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
This event is the first one that initiates after the form opens in Acrobat or Adobe Reader. Any calculation or scripting tasks that require the full form, or that should only run once when the form filler first opens the form, should use this event. For example, you can use the docReady event to check the version of Acrobat or Adobe Reader and return a message to the form filler if the form filler must upgrade the application before filling the form.
enter event
Description
Initiates when a field or subform gains keyboard focus, whether caused by a form filler action (tabbing into a field or clicking in it) or by a script programmatically setting the focus.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to provide help text or other messages to a form filler while entering the current field or subform. For example, if a field requires a value in a specific format, or if filling a field requires special instructions, you can use this event to provide a message to the form filler indicating the special needs. For a detailed example of using the enter event, see Highlighting fields in response to form filler interaction on page 107.
Events
exit event 34
exit event
Description
Initiates when the field or subform loses keyboard focus, whether caused by a form filler action (tabbing to another field or clicking outside it) or by a script programmatically removing the focus. Note: If the purpose of your script is to manipulate the value of the current field, you need to consider attaching your script to the calculate event.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to provide verification of field data as a form filler moves the focus away from a field. For example, if a field requires a value, you can use this event to provide a message to the form filler indicating that the field requires some data before the form can be submitted. For a detailed example of using the exit event, see Highlighting fields in response to form filler interaction on page 107.
form:ready event
Description
Initiates after the form design and data are merged, the finished form exists in memory, and the initialize, calculate, and validate events are complete.
Type
Processing event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to perform tasks after the form design and data are merged but before the layout is established. For example, you can use this event to customize the ordering or placement of subforms on your form before the form is paginated and rendered.
Events
full event 35
full event
Description
Initiates when the form filler attempts to enter more than the maximum allowed amount of content into a field. For example, if the Limit Length property for a field is set to 5, and a form filler attempts to enter the string abcdef, the full event initiates when the form filler types the letter f. Note: The Limit Length property for a field is located in the Field tab in the Object palette.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
Use this event to indicate to a form filler that a field has reached its maximum capacity. For example, you can output a message to the form filler indicating that the field is full and provide any steps that should be taken to correct the issue.
indexChange event
Description
Initiates as a result of a subform being inserted, moved, or removed from the form by merging new data with the form or by using scripting. Note: This event is received only by the subform instances that are controlled by the instance manager; the event is ignored for subform sets.
Type
Processing event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to set properties based on the instance value of a particular object. For example, you can use this event to coordinate the shading of alternate rows in a table.
Events
initialize event 36
initialize event
Description
Initiates for all objects after the form design is merged with data.
Type
Processing event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to perform actions when an object is first created, either as the result of a form filler action or during the form creation process. For example, you can use this event to control settings for new instances of a subform object that a form filler adds to the form by using a button.
layout:ready event
Description
Initiates after the form design and data are merged, the form exists, and the forms layout is applied. At this time, the finished form has not been rendered; therefore, a calculation or script set to run on this event could modify the layout before the forms is rendered. This event also occurs after the form is rendered if a calculation or script changes the data or causes a change to the form in Acrobat or Adobe Reader. Note: Fields in interactive forms that contain the layout:ready event are supported in Acrobat 7 and later.
Type
Processing event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to perform tasks immediately after the form layout is established. For example, you can use this event to determine the number of pages the form contains.
Events
mouseDown event 37
mouseDown event
Description
Initiates when a form filler presses the mouse button at the same time that the pointer is within a field. Note: When a mouseDown event initiates for a text or numeric field, calculations or scripts run immediately. However, the value of the field does not change in response to calculations and scripts until the field loses focus. When a mouseDown event initiates for a document signature field, the event initiates before the signature process begins.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to perform an action as a direct response to a form filler clicking a button, or selecting a radio button or check box on a form. For example, you can use the mouseDown event for a check box to hide and show a field on the form. This event is conceptually similar to the click event and has a similar purpose.
mouseEnter event
Description
Initiates when the form filler moves the pointer into the area of the field, without necessarily pressing the mouse button. This event is not initiated when the pointer moves into the field for a different reason; for example, because an overlapping window closes.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to provide visual feedback to a form filler in conjunction with the mouseExit event. For example, you can use this event to change the border or background color of an object to help visually indicate to form fillers that they are working in a specific field. For a detailed example of using the mouseEnter event, see Highlighting fields in response to form filler interaction on page 107.
Events
mouseExit event 38
mouseExit event
Description
Initiates when a form filler moves the pointer out of the field, even if the form filler is pressing the mouse button. It is not initiated when the pointer moves out of the field for a different reason; for example, because an overlapping window opens.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to provide visual feedback to a form filler in conjunction with the mouseEnter event. For example, you can use this event to return the border or background color of an object to its original value to help visually indicate to form fillers that they are no longer working in a specific field. For a detailed example of using the mouseExit event, see Highlighting fields in response to form filler interaction on page 107.
mouseUp event
Description
Initiates when a form filler releases the mouse button at the same time that the pointer is within a field. Note: When a mouseUp event occurs for a text or numeric field, calculations or scripts run immediately. However, the value of the field does not change in response to calculations and scripts until the field loses focus.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to perform actions as a direct response to a form filler clicking a button, or selecting a radio button or check box on a form. For example, you can use the mouseUp event for a check box to hide and show a field on the form. This event is conceptually similar to the click event and has a similar purpose.
Events
postPrint event 39
postPrint event
Description
Initiates immediately after the rendered form is sent to the printer, spooler, or output destination.
Type
Application event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to display information messages to the form filler after the form is printed. For example, you can create a script on the postPrint event to remind form fillers what steps they need to take to submit the form by hand.
postSave event
Description
Initiates immediately after a form filler saves a form in PDF or XDP format. This event does not initiate when you export a subset of the form (for example, only form data) to XDP.
Type
Application event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to display information messages to the form filler after the form data is saved. For example, you can create a script on the postSave event to remind form fillers how much time remains for them to successfully complete and submit the form.
Events
preOpen event 40
preOpen event
Description
Initiates when a form filler performs an action that causes the drop-down list to appear, such as clicking the arrow icon on the drop-down list or by tabbing into the drop-down list and using the down arrow. This event initiates before the contents of the drop-down list are displayed. Note: This event applies only to the Drop-down List object.
Type
Interactive event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to control the loading of large numbers of list items. For example, you can use this event to load a fixed number of records from a data source into a drop-down list. This improves the performance of the form for the form filler at run time.
prePrint event
Description
Initiates immediately before the process of rendering a form for printing begins. You cannot cancel printing using this event. Caution: Avoid using this event to hide or show form objects. For example, if a form filler has already digitally signed the form, using this event to hide all button objects prior to printing will impact the state of the signature.
Type
Application event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to change the presence of an object to prevent it from printing. For example, you can use this event to hide text or instructions intended for the form filler to use while filling the form online.
Events
preSave event 41
preSave event
Description
Initiates immediately before form data is saved in PDF or XDP format. This event does not initiate when the form data or another subset of the form is exported to XDP.
Type
Application event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to change form data immediately before the data is saved. For example, you can create a script on the preSave event to scan the data and display a reminder message to the form filler if certain required fields remain empty.
preSubmit event
Description
Initiates when a form submits data to the host through the HTTP protocol. At this point, the data is organized into a data set but has not been sent to the host. Calculations and scripts associated with this event can examine and alter the data prior to the form submission. If the calculation or script is set to run on the server, the form sends the data to the server indicating that it should run the calculation or script before performing any additional processing. Note: This event does not distinguish between submissions initiated by instances of clicking buttons or to different URLs. Any script that needs to make these distinctions must include code to determine which button was clicked. In general, the preSubmit event is conceptually similar to the preSave event and serves a similar purpose.
Type
Application event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to change form data immediately before the data is submitted. For example, you can create a script on the preSubmit event to scan the amount of data and display a message to the form filler estimating how long the data submission may take.
Events
validate event 42
validate event
Description
Initiates when the form design and data merge to create your form and when a field loses focus; for example, when a form filler clicks or uses the Tab key to exit a field. This event initiates again each time the value of a field changes. Calculations and scripts placed on the validate event provide a method to perform validations that are more specific than those available through the Value tab of the Object palette. Calculations and scripts on the validate event are required to return true or false (expressed in a format appropriate to the scripting language) corresponding to a validation that succeeds or fails, and must not affect the overall form structure of form values. In addition, calculations and scripts should not attempt to provide feedback to a form filler because that form filler may not be using the form in a client application such as Acrobat. Note: Because validations are performed against the content of the form, they cannot be used to verify presentation formatting caused by field patterns.
Type
Processing event
Support
Client application Acrobat and Adobe Reader HTML browser Availability
Example
You can use this event to verify object values, particularly in situations where object data must conform to specific rules. For example, you can create a script on the validate event to verify that a total cost field on a purchase order form does not have a negative value. For a detailed example of using the validate event, see Setting a field as required at run time on page 105.
Scripting Languages
Description Returns the absolute value of a numeric value or expression. Returns the annual percentage rate for a loan. Locates the starting character position of a string within another string.
None
At(s1, s2)
String.search(s1)
Avg(n1 [, n2... ] )
Evaluates a set of number None values and/or expressions and returns the average of the non-null elements contained within that set. Returns the whole number greater than or equal to a given number. Selects a value from a given set of parameters. Returns the concatenation of two or more strings. Evaluates a set of values and/or expressions and returns the number of non-null elements contained within the set.
Math.ceil(n1)
Ceil(n1)
None
String.concat(s1, s2 [, s3 ... ])
Count(n1 [, n2...])
None
43
Scripting Languages
Differences between FormCalc and JavaScript functions 44
FormCalc function
CTerm(n1, n2, n3)
Description Returns the number of periods needed for an investment earning a fixed, but compounded, interest rate to grow to a future value. Returns the current system date as the number of days since the epoch. Returns the number of days since the epoch, given a date string. Returns a date format string, given a date format style. Returns the decoded version of a given string.
Date()
Date.getDate()
Note: The JavaScript Date object does not use the epoch as a reference point. The JavaScript Date object does not use the epoch as a reference point. None
Date2Num(d1 [, f1 [, k1 ] ] )
DateFmt([ n1 [, k1 ] ] )
Decode(s1 [, s2 ] )
Partial support JavaScript only supports URL encoded values that contain no escape characters. Partial support JavaScript only supports URL encoded values that contain no escape characters.
eval(s1)
Encode(s1 [, s2 ] )
Eval() Exists(v1)
Returns the value of a given form calculation. Determines whether the given parameter is a valid reference syntax to an existing object. Returns the largest whole number that is less than or equal to the given value. Formats the given data according to the specified picture format string.
None
Floor(n1)
Math.floor(n1)
Format(s1, s2)
None
Scripting Languages
Differences between FormCalc and JavaScript functions 45
FormCalc function
FV(n1, n2, n3)
Description Returns the future value of consistent payment amounts made at regular intervals at a constant interest rate. Downloads the contents of the given URL. Determines whether the given parameter is a valid reference syntax with a non-null, non-empty, or non-blank value. Returns the amount of interest paid on a loan over a set period of time.
Get(s1) HasValue(v1)
None None
None
IsoDate2Num(d1)
Returns the number of None days since the epoch, given an valid date string. Returns the number of milliseconds since the epoch, given a valid time string. Extracts a specified number of characters from a string, starting with the first character on the left. Returns the number of characters in a given string. Returns a localized date format string, given a date format style. Returns a localized time format string, given a time format style. Converts all uppercase characters within a specified string to lowercase characters. None
IsoTime2Num(d1)
Left(s1, n1)
String.substring(n1, n2)
Len(s1)
String.length
LocalDateFmt( [ n1 [, k1 ] ] )
None
LocalTimeFmt( [ n1 [, k1 ] ] )
None
Lower(s1 [, k1 ] )
String.toLowerCase(s1)
Scripting Languages
Differences between FormCalc and JavaScript functions 46
FormCalc function
Ltrim(s1)
Description Returns a string with all leading white space characters removed.
JavaScript method equivalent None Note: You can use JavaScript regular expressions to perform this operation.
Math.max(n1, n2)
Max(n1 [, n2... ] )
Returns the maximum value of the non-null elements in the given set of numbers. Returns the minimum value of the non-null elements of the given set of numbers. Returns the modulus of one number divided by another. Returns the net present value of an investment based on a discount rate and a series of periodic future cash flows. Returns a date string, given a number of days since the epoch. Returns a GMT time string, given a number of milliseconds from the epoch. Returns a time string, given a number of milliseconds from the epoch. Returns true (1) if a value is in a given set, and false (0) if it is not.
Min(n1 [, n2... ] )
Math.min(n1, n2)
Mod(n1, n2)
NPV(n1, n2 [, ... ] )
None
Num2Date(n1[, f1 [, k1 ] ] )
None
Num2GMTime(n1 [,f1 [, k1 ] ] )
None
Num2Time(n1 [,f1 [, k1 ] ] )
None
Oneof(s1, s2 [, s3... ] )
method.
Parse(s1, s2)
None
Scripting Languages
Differences between FormCalc and JavaScript functions 47
FormCalc function
Pmt(n1, n2, n3)
Description Returns the payment for a loan based on constant payments and a constant interest rate. Posts the given data to the specified URL. Returns the amount of principal paid on a loan over a period of time. Uploads the given data to the specified URL. Returns the present value of an investment of periodic constant payments at a constant interest rate. Returns the compound interest rate per period required for an investment to grow from present to future value in a given period. Returns a reference to an existing object. Replaces all occurrences of one string with another within a specified string. Extracts a number of characters from a given string, beginning with the last character on the right. Evaluates a given numeric value or expression and returns a number rounded to the given number of decimal places. Returns a string with all trailing white space characters removed.
None None
None None
None
Ref() Replace(s1, s2 [, s3 ] )
None
String.replace(s1, s2)
Right(s1, n1)
String.substring(n1, n2)
Round(n1 [, n2 ] )
Math.round(n1)
Rtrim(s1)
None Note: You can use JavaScript regular expressions to perform this operation.
Scripting Languages
Differences between FormCalc and JavaScript functions 48
FormCalc function
Space(n1)
Description Returns a string consisting of a given number of blank spaces. Converts a number to a character string. FormCalc formats the result to the specified width and rounds to the specified number of decimal places. Inserts a string into another string. Extracts a portion of a given string. Returns the sum of the non-null elements of a given set of numbers. Returns the number of periods needed to reach a given future value from periodic constant payments into an interest-bearing account. Returns the current system time as the number of milliseconds since the epoch. Returns the number of milliseconds since the epoch, given a time string. Returns a time format, given a time format style. Returns the units of a unitspan. A unitspan is a string consisting of a number followed by a unit name. Returns the numeric value of a measurement with its associated unitspan, after an optional unit conversion.
Str(n1 [, n2 [, n3 ] ] )
String(n1)
or
Number.toString(radix)
None
String.substring(n1, n2)
None
None
Time()
Date.getTime()
Note: The JavaScript Date object does not use the epoch as a reference point. None
Time2Num(d1 [, f1 [, k1 ] ] )
TimeFmt([n1 [, k1 ] ] ) UnitType(s1)
None None
UnitValue(s1 [, s2 ] )
None
Scripting Languages
Using FormCalc 49
FormCalc function
Upper(s1 [, k1 ] )
Description Converts all lowercase characters within a string to uppercase. Returns a Universally Unique Identifier (UUID) string to use as an identification method. Returns true (1) if the test value is within a given range, and false (0) if it is not. Returns the English text equivalent of a given number.
Uuid(n1)
None
String.search(s1)
WordNum(n1 [, n2 [, k1 ] ] )
None
Using FormCalc
About using FormCalc
FormCalc is a simple yet powerful calculation language modeled on common spreadsheet software. Its purpose is to facilitate fast and efficient form design without requiring a knowledge of traditional scripting techniques or languages. With the use of a few of the built-in functions, users new to FormCalc can expect to quickly create forms that save end users from performing time-consuming calculations, validations, and other verifications. In this manner you can create a basic set of rules for the form design that allows the resulting form to react according to the data it comes into contact with. Within LiveCycle Designer ES, FormCalc is the default scripting language in all scripting locations with JavaScript as the alternative. For information on setting your default scripting language, see About the Script Editor on page 11. Caution: If you are developing forms for use with a server-based process (for example, using LiveCycle Forms ES), with the intent of rendering your forms in HTML, you should develop your calculations and scripts in JavaScript. FormCalc calculations are not valid in HTML browsers, and are removed prior to the form being rendered in HTML. FormCalc treats each new line in the Script Editor as a new expression to evaluate.
Scripting Languages
To attach a FormCalc function to an object 50
5. Select the desired function and press Enter. 6. Replace the default function syntax notation with your own set of values. 7. Click the Preview PDF tab to test the form.
Replacement values A valid date string (for example, 03/15/1996) A valid date format string (for example, MM/DD/YYYY) A valid locale identifier (for example, fr_FR) A valid numeric value. Note that the range of valid values varies from function to function. A valid unit of measurement (for example, in for inches). A valid reference syntax. All values are required. No values are required, but you can choose to specify just n, or both n and k. n1 is required, but you can choose to specify an unlimited number of additional values. d is required, but you can choose to also specify f or both f and k.
For more information and examples of valid syntax notation values, see the appropriate FormCalc functions in LiveCycle Designer ES Help.
Scripting Languages
Creating basic calculations 51
Each simple expression evaluates to a single value by following a traditional order of operations, even if that order is not always obvious from the expression syntax. For example, the following sets of expressions produce equivalent results: Expression
"abc" 2 - 3 * 10 / 2 + 7 (10 + 2) * (5 + 4) 0 and 1 or 2 > 1 2 < 3 not 1 == 1
Equivalent to
"abc" 2 - (3 * 10 / 2) + 7 (10 + 2) * (5 + 4) (0 and 1) or (2 >1) (2 < 3) not (1 == 1)
Result
abc -6 108 1 (true) 0 (false)
As implied in the previous table, all FormCalc operators carry a certain precedence when they appear within expressions. The following table illustrates this operator hierarchy. Precedence Highest Operator = (Unary) - , + , not *,/ +,< , <= , > , >= , lt , le , gt , ge == , <> , eq , ne & , and Lowest | , or
Scripting Languages
Creating basic calculations 52
All of the previous examples are valid, simple expressions that you can add to a form field or object that will accept calculations and scripts. For example, if you create a new form in LiveCycle Designer ES with a single numeric field, add the following calculation to the calculate event in the Script Editor.
Then, when you click the Preview PDF tab to view the completed form, the value of the simple expression appears in the text field.
If the value does not appear in the preview, ensure that your simple expression appears in the calculate event of the form design object. You need to also ensure that you installed LiveCycle Designer ES and Acrobat correctly.
Scripting Languages
Using JavaScript 53
Using JavaScript
About using JavaScript
To allow form designers more flexibility and scripting power, LiveCycle Designer ES supports the use of JavaScript version 1.6 or earlier in all situations that support scripting. Form developers familiar with JavaScript will be able to take their existing expertise and apply it directly to LiveCycle Designer ES. LiveCycle Designer ES provides a number of properties and methods that enhance JavaScript to allow you to access field and object values. These properties and methods combine with the LiveCycle Designer ES reference syntax to provide you with easy manipulation of form values and data. Note: The Script Editor does not provide syntax error checking for scripts created using JavaScript. In addition, statement completion options do not appear for standard JavaScript objects or methods.
Using the host and event models to test and debug your form.
In addition to the resources available in the LiveCycle Designer ES Help, the LiveCycle ES Developer Center contains extensive scripting resources and documentation. The developer center is located at www.adobe.com/devnet/livecycle/.
Scripting Languages
To attach a JavaScript script to an object 54
6. Click the Preview PDF tab to test the form. The text should appear red for the new button object when the form is displayed in the Preview PDF tab.
Variables
About variables
You can define form variables in LiveCycle Designer ES to store specific information in a central, accessible location. A variable typically acts as a placeholder for text that you might have to change in the future. For example, a variable can store the text of a message box title. When the text needs to change, all you have to do is open the affected form or template and update the text once through the variable definition. LiveCycle Designer ES automatically propagates the new text across all instances of the inserted variable. Keep in mind that form variables are defined outside of the Script Editor, and are accessible by scripts on all objects on a form, as opposed to scripting variables that you create in a specific FormCalc or JavaScript script. You can create, view, and delete variables without using scripting. However, you must use scripting to access the values stored by variables and manipulate them, or to apply the values to objects on your form. Note: Form variable values reset each time you open a form. Before you create a variable, decide the name of the variable and the text that it will contain. Variable definitions are saved with the form or template.
Naming variables
At run time, naming conflicts occur when the names of variables are identical to those used as XML Form Object Model properties, methods, or form design field names. These conflicts can cause scripts to return unexpected values; therefore, it is important to give each variable a unique name. Here a couple of examples:
Use the variable name fieldWidth and fieldHeight instead of x and y. Use the form design object name clientName instead of name.
Note: Variable names are case-sensitive and should not contain spaces.
3. In the Variables list, type a unique name for the variable and press Enter. Variable names are case-sensitive and should not contain spaces. 4. Click once in the box to the right and type the text you want to associate with the variable.
55
Variables
To view a text variable definition 56
Variables
Using variables in calculations and scripts 57
In FormCalc, you can access the variable values in the same manner that you access field and object values. In this example, the values are assigned to three separate fields:
TextField1 = firstName TextField2 = lastName NumericField1 = age
You can also use variables in FormCalc functions in the same way, as shown in this example:
Concat( "Dear ", firstName, lastName )
In JavaScript, you reference variable values by using the .value property instead of the .rawValue property that is used for field and object values, as shown in this example:
TextField1.rawValue = firstName.value;
The names of the parent objects in the form hierarchy that is used to navigate to a specific field or object. You can use the Hierarchy palette and Data View palette to determine the location of an object relative to other objects in the form and in any associated data. The name of the object you want to reference. The the name of the property or method you want to access. This section may also include XML Form Object Model objects that precede the property or method in the structure but that do not appear as objects in the Hierarchy palette.
For example, the following illustration shows the reference syntax for accessing the value of a text field on a form design that uses the default object-naming conventions: Form hierarchy objects Object name Property or method name
xfa.form.form1.#subform.TextField1.rawValue
Note: By default, the subform object that represents the first page of a new form is unnamed. In the reference syntax above, the unnamed subform is represented by #subform. The reference syntax notation structure varies slightly, depending on the specific situation. For example, a fully qualified reference syntax works in any situation; however, in some cases, you can use a shortened reference syntax or a reference syntax shortcut to reduce the size of the syntax.
58
Abbreviated The reference syntax is shortened either because of the relative positioning of the calculation or script that contains the reference syntax and the object syntax references, or because shortcuts are used. In general, although an abbreviated reference syntax is faster to create, the disadvantage is that it works only as long as the objects remain in the same positions relative to each other. For example, this illustration shows the hierarchy of a sample purchase order form.
This illustration shows a fully qualified reference syntax, for both FormCalc and JavaScript, to access the value of the txtCondition field. This reference syntax could be used as part of a calculation or script on any object on the form. Root Node Model Form design root node Page object Subform name Object name Property or method name
xfa.form.form1.purchaseOrder.total.txtCondition.rawValue
Note: Even though the reference syntax is common to both FormCalc and JavaScript, you must observe the conventions for each scripting language. For example, the reference syntax in the example above works as is for FormCalc; however, you would need to include a trailing semicolon (;) character for JavaScript.
If two objects exist in the same container, such as a subform, they are referred to as sharing the same context. Where objects exist in the same context, you can use an abbreviated reference syntax that includes only the name of the object followed by the property or method you want to access. For example, using the example from above, the following abbreviated reference syntax accesses the value of the txtCondition field from any of the fields in the total subform:
txtCondition.rawValue
If two objects exist in different containers, they do not share the same context. In this case, you can use an abbreviated reference syntax; however, the syntax must begin with the name of the highest level container object that the two objects do not have in common. For example, using the hierarchy above, the following abbreviated reference syntax accesses the value of the address field from the txtCondition field:
header.address.rawValue
Due to the way the XML Form Object Model is structured, some object properties and methods exist on child objects of the objects on the form. These child objects exist only as part of the XML Form Object Model and do not appear in the Hierarchy and Data View palettes. To access these properties and methods, you must include the child objects in the reference syntax. For example, the following reference syntax sets the tool tip text for the txtCondition field:
txtCondition.assist.toolTip.value = "Conditions of purchase." // FormCalc txtCondition.assist.toolTip.value = "Conditions of purchase."; // JavaScript
For more information about the XML Form Object model objects and their structure, see the LiveCycle Designer ES Scripting Reference at http://www.adobe.com/go/learn_lc_scriptingReference.
For example, when you create a new blank form, by default, the name of the subform that represents the page of the form is an unnamed subform with an occurrence value of 0. The following illustration shows the form hierarchy on a new form with default object naming.
The untitled subform that represents the first page of the form has an occurrence number of 0. In this situation, both of the following reference syntaxes access the value of the text field in the form hierarchy above on a new form that uses default naming conditions:
xfa.form.form1.#subform.TextField1.rawValue xfa.form.form1.#subform[0].TextField1.rawValue
Note: By default, if you do not specify an occurrence value for an object, the reference syntax accesses the first occurrence of that object. FormCalc recognizes the fully qualified reference syntax above and interprets it directly. To access the same value by using JavaScript, you must use one of these forms of the resolveNode scripting method:
xfa.resolveNode("xfa.form.form1.#subform.TextField1").rawValue; xfa.resolveNode("xfa.form.form1.#subform[0].TextField1").rawValue;
If you add a new page to your form, by default, the name of the subform that represents the new page is unnamed; however, the occurrence value for the new subform is set to 1. You can specify the new unnamed subform by using a similar reference syntax as above:
xfa.form.form1.#subform[1].TextField1.rawValue // FormCalc xfa.resolveNode("xfa.form.form1.#subform[1].TextField1").rawValue; // JavaScript
Note: The statement completion options available in the Script Editor include unnamed objects at the beginning of the list. Objects that have multiple occurrence values appear only once in the list, representing the first occurrence of the object. If you want to access an occurrence value other that the first occurrence, you must manually add the occurrence value to the reference syntax. You can use the resolveNode method to reference objects within other reference syntax statements. This can help to reduce the amount of scripting you need to reference a particular object, property, or method. For example, you could simplify the reference syntax that points to a text field on the second page of your form to the following statement:
xfa.form.form1.resolveNode("#subform[1].TextField1").rawValue; // JavaScript
Similarly, you can use the dollar sign ($) shortcut and the keyword this to replace the name of the current object when accessing object properties in calculations and scripts. For example, the following reference syntax changes the tool tip text associated with the current object:
$.assist.toolTip.value = "This is some tool tip text." // FormCalc this.assist.toolTip.value = "This is some tool tip text."; // JavaScript
The above example sets the value of the current field or object to Tony Blue.
$data
is equivalent to
xfa.datasets.data.purchaseOrder.total $event
is equivalent to
xfa.event.name $form
is equivalent to stating
xfa.form.purchaseOrder.tax $host
is equivalent to
xfa.host.messageBox("Hello world")
Notation
$layout
Description Represents the root of the layout model xfa.layout. For example,
$layout.ready
is equivalent to stating
xfa.layout.ready $record
Represents the current record of a collection of data, such as from an XML file. For example,
$record.header.txtOrderedByCity
references the txtOrderedByCity node within the header node of the current XML data.
$template
is equivalent to
xfa.template.purchaseOrder.item !
is equivalent to
xfa.datasets.data *
Selects all form objects within a given container, such as a subform, regardless of name, or selects all objects that have a similar name. For example, the following expression selects all objects named item on a form:
xfa.form.form1.item[*]
Note: You can use the * (asterisk) syntax with JavaScript if it used with the resolveNode method. For more information about the resolveNode method, see LiveCycle Designer ES Help, or see the LiveCycle Designer ES Scripting Reference at http://www.adobe.com/go/learn_lc_scriptingReference.
Notation
..
Description You can use two dots at any point in your reference syntax to search for objects that are a part of any subcontainer of the current container object, such as a subform. For example, the expression Subform_Page..Subform2 means locate the node Subform_Page (as usual) and find a descendant of Subform_Page called Subform2.
is equivalent to
Subform_Page.Subform1[0].Subform3.TextField2[0]
because TextField2[0] is in the first Subform1 node that FormCalc encounters on its search. As a second example,
Subform_Page..Subform3[*]
returns all four TextField2 objects. Note: You can use the .. (double period) syntax with JavaScript if it used with the resolveNode method. For more information about the resolveNode method, see LiveCycle Designer ES Help, or see the LiveCycle Designer ES Scripting Reference at http://www.adobe.com/go/learn_lc_scriptingReference.
#
The number sign (#) notation is used to denote one of the following items in a reference syntax:
An unnamed object. For example, the following reference syntax accesses an unnamed subform:
xfa.form.form1.#subform
Specify a property in a reference syntax if a property and an object have the same name. For example, the following reference syntax accesses the name property of a subform if the subform also contains a field named name:
xfa.form.form1.#subform.#name
Note: You can use the # (number sign) syntax with JavaScript if it used with the resolveNode method. For more information about the resolveNode method, see LiveCycle Designer ES Help, or see LiveCycle Designer ES Scripting Reference at http://www.adobe.com/go/learn_lc_scriptingReference.
Notation
[ ]
Description The square bracket ([ ]) notation denotes the occurrence value of an object. To construct an occurrence value reference, place square brackets ([ ]) after an object name, and enclose within the brackets one of the following values:
[ n ], where n is an absolute occurrence index number beginning at 0. An occurrence number that is out of range does not return a value. For example, xfa.form.form1.#subform.Quantity[3] refers to the fourth occurrence of the Quantity object.
[ +/- n ], where n indicates an occurrence relative to the occurrence of the object making the reference. Positive values yield higher occurrence numbers, and negative values yield lower occurrence numbers. For example, xfa.form.form1.#subform.Quantity[+2]
This reference yields the occurrence of Quantity whose occurrence number is two more than the occurrence number of the container making the reference. For example, if this reference was attached to the Quantity[2]object , the reference would be the same as
xfa.template.Quantity[4]
If the computed index number is out of range, the reference returns an error. The most common use of this syntax is for locating the previous or next occurrence of a particular object. For example, every occurrence of the Quantity object (except the first) might use Quantity[-1] to get the value of the previous Quantity object.
[*] indicates multiple occurrences of an object. The first named object is found, and objects of the same name that are siblings to the first are returned. Note that using this notation returns a collection of objects. For example, xfa.form.form1.#subform.Quantity[*]
This expression refers to all objects with a name of Quantity that are siblings to the first occurrence of Quantity found by the reference. Note: In language-specific forms for Arabic, Hebrew, Thai, and Vietnamese, the reference syntax is always on the right (even for right-to-left languages).
Notation
[ ] (Continued)
Description
Using the tree for reference, these expressions return the following objects:
Subform_Page.Subform1[*] returns both Subform1 objects. Subform_Page.Subform1.Subform3.TextField2[*] returns two TextField2 objects. Subform_Page.Subform1 resolves to the first Subform1 object on the left, and TextField2[*] evaluates relative to the Subform3 object. Subform_Page.Subform1[*].TextField1 returns both of the TextField1 instances. Subform_Page.Subform1[*] resolves to both Subform1 objects, and TextField1 evaluates relative to the Subform1
objects.
Subform_Page.Subform1[*].Subform3.TextField2[1] returns the second and fourth TextField2 objects from the left. Subform_Page.Subform1[*] resolves to both Subform1 objects, and TextField2[1] evaluates relative to the Subform3 objects. Subform_Page.Subform1[*].Subform3[*] returns both instances of the Subform3 object. Subform_Page.* returns both Subform1 objects and the Subform2 object. Subform_Page.Subform2.* returns the two instances of the NumericField2 object.
Note: You can use the [ ] (square bracket) syntax with JavaScript if it used with the resolveNode method. For more information about the resolveNode method, see LiveCycle Designer ES Help, or see LiveCycle Designer ES Scripting Reference at http://www.adobe.com/go/learn_lc_scriptingReference.
Form level object Subform level object Subform level script object Form level script object
67
The Script Editor is displayed with both a Script Object value in the Show list and a JavaScript value in the Language list. You cannot change either of these values.
2. Enter your script in the Script Source field. 3. Click the Preview PDF tab to test the form.
Example
For example, create a script object called feedback that contains the following function:
function emptyCheck(oField) { if ((oField.rawValue == null) || (oField.rawValue == "")) { xfa.host.messageBox("You must input a value for this field.", "Error Message", 3); } }
3. Apply the new script to the form object and test it by previewing the form using the Preview PDF tab. Similar to referencing other objects on a form, you must provide a valid syntax when referencing the script object that includes where it exists within the form hierarchy. For more information about referencing objects in scripting, see Referencing object properties and values on page 58.
Example
For example, using the script object example from To add script to a script object on page 67, place the following JavaScript script on the exit event for a text field. Test the form using the Preview PDF tab.
feedback.emptyCheck(this);
Source File
Sets the source file for the fragment reference. This property is visible only when the selected object is a fragment reference.
Fragment Name
Sets the name of the fragment. You can click the Frag Info button to view the fragment information.
This property is visible when a fragment reference or a fragment that is defined in a source file is selected. When the selected object is a fragment reference, this property does not appear if the source file is not specified. The Fragment Name list includes all the fragments in the specified source file. The Custom option directly supports setting a SOM expression or an ID value as the fragment reference and supports the implementation in the XML Forms Architecture.
3. To use a different fragment name, in the Name box, type a name for the fragment. 4. (Optional) In the Description box, type a description of the fragment. 5. Select a method for creating the fragment:
To define the fragment in a separate XDP file that is stored in the Fragment Library, select Create Fragment In Fragment Library and go to step 6. To define the fragment in the current file, select Create New Fragment in Current Document and go to step 9.
6. In the Location list, select the Fragment Library in which to save the fragment file. 7. To use a different file name, in the File Name box, type the file name for the fragment. 8. If you do not want to replace the selection with the new fragment, deselect Replace Selection With Reference To New Form Fragment. 9. Click OK.
1. In the fragment library, select the script fragment. 2. Drag the fragment to a subform or variables object in the Hierarchy palette.
To insert a script fragment from the Insert menu:
1. Select Insert > Fragment. 2. Navigate to the file that contains the fragment. 3. Select the file and click OK. The fragment appears as a child of the variables object in the root subform
10
Using the Warnings tab in the Report palette, you can view any errors or messages generated by LiveCycle Designer ES as you design a form. For more information about using the Warnings tab and the LiveCycle Designer ES workspace to debug your scripts, see Using the workspace to debug calculations and scripts on page 14. Using the Log tab, you can view validation messages, JavaScript or FormCalc scripting execution errors, and design-time form rendering errors generated by LiveCycle Designer ES when you import or save a form, or preview a form using the Preview PDF tab. Using the XML Form Object Model messageBox method to output information from an interactive form into a dialog box at run time. For certain types of debugging, you may want to output information, such as field values or messages, into a text field on your form design. For example, you can append new messages or values to the value of a text field to create a log that you can refer to when resolving issues.
If you use Acrobat Professional, you can use the JavaScript Debugger from Acrobat to test your form scripts. The JavaScript Debugger includes the JavaScript Console, which you can use to test portions of JavaScript code in the Preview PDF tab. The JavaScript Console provides an interactive and convenient interface for testing portions of JavaScript code and experimenting with object properties and methods. Because of its interactive nature, the JavaScript Console behaves as an editor that supports the execution of single lines or blocks of code. For more information about the JavaScript Console and the JavaScript Debugger, see Developing Acrobat Applications Using JavaScript at http://www.adobe.com/go/learn_lc_AcrobatDeveloper (English only).
71
FormCalc
xfa.host.messageBox(Concat("The value of NumericField1 is: ", NumericField1), "Debugging", 3)
JavaScript
xfa.host.messageBox("The value of NumericField1 is: " + NumericField1.rawValue, "Debugging", 3);
Caution: The messageBox method returns an integer value representing the button that the form filler selects in the message box dialog. If you attach the messageBox method to the calculate event of a field object, and the messagebox method is the last line of the script, the field displays the return value of the messageBox method at run time. In some situations, such as if you want to return a message box during a calculate event, you can take advantage of the alert method from the JavaScript Object Model from Acrobat. For example, the following script returns the value of a text field:
var oField = xfa.resolveNode("TextField1").rawValue; app.alert(oField);
For more information about the alert method and the JavaScript Object Model from Acrobat, see Developing Acrobat Applications Using JavaScript at http://www.adobe.com/go/learn_lc_AcrobatDeveloper (English only).
9. Click OK to close the Preferences dialog box. 10. Quit Acrobat Professional. 11. In LiveCycle Designer ES, click the Preview PDF tab. 12. Press Ctrl+J to open the JavaScript Debugger.
To evaluate a portion of a line of code, highlight the portion in the console window and press either Enter on the numeric keypad or Ctrl+Enter on the regular keyboard. To evaluate a single line of code, make sure the cursor is positioned in the appropriate line in the console window and press either Enter on the numeric keypad or Ctrl+Enter on the regular keyboard. To evaluate multiple lines of code, highlight those lines in the console window and press either Enter on the numeric keypad or Ctrl+Enter on the regular keyboard.
In all cases, the result of the most recently evaluated JavaScript script is displayed in the console window. After evaluating each JavaScript script, the console window prints out undefined, which is the return value of the statement. Notice that the result of a statement is not the same as the value of an expression within the statement. The return value undefined does not mean that the value of script is undefined; it means that the return value of the JavaScript statement is undefined. Click Clear (the trash can icon) at the lower right of the console to delete any contents that appear in the console window.
For more information about the console.println method and the JavaScript Object Model from Acrobat, see Developing Acrobat Applications Using JavaScript at http://www.adobe.com/go/learn_lc_AcrobatDeveloper (English only).
11
Methods
beep exportData gotoURL importData messageBox pageDown pageUp print resetData response setFocus
For more information about the host scripting model properties and methods, see the LiveCycle ES Developer Center located at www.adobe.com/devnet/livecycle/.
75
or
app.launchURL(URL); doc.importXFAData(cPath) app.language app.alert(cMsg [, nIcon [, nType [, cTitle ] ] ]) none doc.numPages doc.pageNum++ doc.pageNum-app.platform doc.print([ bUI [, nStart [, nEnd [, bSilent [, bShrinkToFit [, bPrintAsImage [, bReverse [, bAnnotations ] ] ] ] ] ] ] ]) doc.resetForm([ aFields ]) app.response(cQuestion [, cTitle [, cDefault [, bPassword ] ] ]) field.setFocus()
xfa.host.importData( [ STRING param ] ) xfa.host.language xfa.host.messageBox(STRING param1 [, STRING param2 [, INTEGER param3 [, INTEGER param4 ] ] ]) xfa.host.name xfa.host.numPages xfa.host.pageDown() xfa.host.pageUp() xfa.host.platform xfa.host.print(BOOLEAN param1, INTEGER param2, INTEGER param3, BOOLEAN param4, BOOLEAN param5, BOOLEAN param6, BOOLEAN param7, BOOLEAN param8) xfa.host.resetData( [ STRING param ] ) xfa.host.response( STRING param1 [, STRING param2 [, STRING param3 [, BOOLEAN param4] ] ]) xfa.host.setFocus( STRING param )
(Deprecated)
xfa.host.title xfa.host.variation xfa.host.version doc.title app.viewerVariation app.viewerVersion
12
Methods
emit reset
For more information about the event scripting model properties and methods, see the Adobe LiveCycle Designer ES Developer Center located at www.adobe.com/devnet/livecycle/designing_forms.html.
77
13
78
You can also have the form send itself by email by adding the following script to the click event of a button:
var myDoc = event.target; myDoc.mailDoc(true);
Note: In LiveCycle Designer ES, you must ensure that the scripting language for the event is set to JavaScript so that the script will execute correctly at run time. You can also use references to the JavaScript objects in Acrobat in your reference syntax. For example, the following script gets the signed state of a document signature field and takes an action based on the state:
// Proceed if the current field is not signed. var oState = event.target.getField("form1[0].#subform[0].SignatureField1[0]") .signatureValidate(); //Get the field's signed state. if (oState == 0) { ... }
Note: This example uses a fully qualified reference syntax to reference the text For more information about referencing form design objects, see Referencing object properties and values on page 58. When working with JavaScript from Acrobat in LiveCycle Designer ES, remember these points:
In LiveCycle Designer ES, use event.target to access the Doc JavaScript object from Acrobat. In Acrobat, the this object is used to reference the Doc object; however, in LiveCycle Designer ES, the this object refers to the form design object to which the script is attached.
The Script Editor has no statement completion for JavaScript objects from Acrobat. See the JavaScript for Acrobat API Reference at http://adobe.com/go/learn_lc_AcrobatDeveloper.
For more information about converting Acrobat scripting to LiveCycle Designer ES, see the article Converting Acrobat JavaScript for Use in LiveCycle Designer ES Forms in the LiveCycle ES Developer Center at http://www.adobe.com/go/learn_lc_AcrobatDeveloper.
JavaScript in Acrobat
Comments
Annot object properties and methods All properties and methods Yes None Only forms with a fixed layout support the annotation layer.
No
None
LiveCycle Designer ES includes the execCalculate method which initiates the calculate event. See the language property.
xfa.host.language
None
xfa.host.platform
None None
xfa.host.appType xfa.host.variation
JavaScript in Acrobat
viewerVersion app object methods addMenuItem addSubMenu addToolButton alert beep browseForDoc clearInterval clearTimeOut execDialog execMenuItem
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
None None None None None Executes the specified menu command. Use this method in LiveCycle Designer ES for File menu commands.
None None None None None None None LiveCycle Designer ES includes the gotoURL method that loads a specified URL into the client application, such as Acrobat or Adobe Reader.
JavaScript in Acrobat
newDoc
Comments This method can only be executed during batch, console, or menu events.
newFDF openDoc openFDF popUpMenuEx popUpMenu removeToolButton response setInterval setTimeOut trustedFunction trustPropagatorFunction
None None None None This method is only available during batch, console, and application initialization.
Yes
None
JavaScript in Acrobat
dirty
Comments This JavaScript script for LiveCycle Designer ES saves a copy of a form and tests whether the form has changed:
var sOrigXML = xfa.data.saveXML; if (sOrigXML != xfa.data.saveXML) {...}
disclosed documentFileName dynamicXFAForm external filesize hidden icons keywords layout media metadata modDate mouseX mouseY noautocomplete nocache numFields
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
None None None None None None None None None None
xfa.form.desc
The pageContent method returns a list of all objects of a particular type. However, you must execute the method for body pages and master pages to scan the entire form.
JavaScript in Acrobat
numPages
Comments The numPages property returns the page count for the rendered form in the client. See also the absPageCount and pageCount methods. See the currentPage property. See the currentPage property or the pageUp method. See the currentPage property or the pageDown method.
or
xfa.layout.absPageCount() xfa.layout.pageCount()
pageNum pageNum--
Yes Yes
xfa.host.currentPage xfa.host.currentPage--
or
xfa.host.pageUp() pageNum++
Yes
xfa.host.currentPage++
or
xfa.host.pageDown() path securityHandler templates
Yes Yes No
None None None Use subform objects in LiveCycle Designer ES, and use properties and methods to add, remove, move, and set subform instances. See the title property.
Yes
xfa.host.title
Yes No
None None You must use forms that have a fixed layout in LiveCycle Designer ES, and then use the instanceManager object to add, remove, and set the number of instances of a particular object.
JavaScript in Acrobat
addThumbnails addWatermarkFromFile addWatermarkFromText addWeblinks appRightsSign appRightsValidate bringToFront calculateNow
JavaScript-equivalent in LiveCycle Designer ES None None None None None None None
xfa.form.recalculate(1);
Comments
or
execCalculate()
The recalculate method forces a specific set of scripts on calculate events to initiate. Boolean value indicates whether True (default) - all calculation scripts initiate; or False - only pending calculation scripts initiate. Note: LiveCycle Designer ES calculate object controls whether a form filler can override a fields calculated value. Alternatively, you can use the execCalculate method for each object for which you want to force a recalculation.
Yes Yes No
None None None LiveCycle Designer ES forms do not have an equivalent to the concept of an Acrobat template. You must use subform objects in LiveCycle Designer ES.
JavaScript in Acrobat
deletePages
Comments In LiveCycle Designer ES, you can use the instanceManager object to remove the subform object that represents a page of your form.
None None None None This method is only available in the JavaScript Console of the JavaScript Debugger in Acrobat or during batch processing. The exportData method exports an XML or XDP file instead of an FDF file. The exportData method exports an XML or XDP file instead of an FDF file.
exportAsFDF
No
xfa.host.exportData()
exportAsXFDF
No
xfa.host.exportData()
exportDataObject exportXFAData
Yes No
None
xfa.host.exportData()
The exportData method exports an XML or XDP file instead of an FDF file.
The resolveNode method accesses the specified object in the source XML of the form.
getLegalWarnings getLinks
Yes No
None None
JavaScript in Acrobat
getNthFieldName
JavaScript-equivalent in LiveCycle Designer ES You must loop through all objects with a similar class name until you reach the nth occurrence. None None None None None None None None None None None
xfa.host.gotoURL( "http://www.adobe.com");
getNthTemplate getOCGs getOCGOrder getPageBox getPageLabel getPageNthWord getPageNthWordQuads getPageNumWords getPageRotation getPrintParams getTemplate getURL gotoNamedDest importAnFDF importAnXFDF importDataObject importIcon importTextData importXFAData insertPages mailDoc mailForm movePage newPage openDataObject print
No Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes No No Yes Yes Yes Yes No No Yes No No No Yes Yes
JavaScript in Acrobat
removeDataObject removeField removeIcon removeLinks removeScript removeTemplate removeThumbnails removeWeblinks replacePages resetForm
JavaScript-equivalent in LiveCycle Designer ES None None None None None None None None None
xfa.host.resetData()
Comments
or
xfa.event.reset()
The resetData method resets all field values on a form to the default values. The reset method resets all properties within the event model. In LiveCycle Designer ES, the file must be saved at the application level. These scripts are examples of saving at the application level:
app.executeMenuItem ("SaveAs");
saveAs
Yes
None
or
var myDoc = event.target; myDoc.saveAs(); spawnPageFromTemplate setAction setPageLabel setPageRotation setPageTabOrder
No No Yes No No
None None None None None In LiveCycle Designer ES, select Edit > Tab Order to set the tab order.
setScript
No
None
JavaScript in Acrobat
submitForm event object properties change targetName field object properties comb charLimit
JavaScript-equivalent in LiveCycle Designer ES Use one of the submit button objects in LiveCycle Designer ES.
Comments
Yes Yes
xfa.event.change xfa.event.target
No No
None
this.value.#text.maxChars
In forms that have a fixed layout, character limit can be set in the LiveCycle Designer ES workspace. You can set fields on forms whose layout expands to accommodate all data. You can also set the presence property in the LiveCycle Designer ES workspace. Note: You cannot use the prePrint event to change the presence of an object prior to printing.
display = display.noView
No
display = display.noPrint
No
You can also set the presence property in the LiveCycle Designer ES workspace. Note: You cannot use the prePrint event to change the presence of an object prior to printing.
defaultValue
No
None
Set the default field value in the LiveCycle Designer ES workspace. Set the export value in the LiveCycle Designer ES workspace.
exportValues
No
None
JavaScript in Acrobat
fillColor hidden
Comments See the fillColor property. You can also set the presence property in the LiveCycle Designer ES workspace. See the multiLine property. LiveCycle Designer ES contains a Password Field that you can use for passwords on a form. Not applicable for LiveCycle Designer ES forms. See the relevant property. Grouped radio buttons in LiveCycle Designer ES are mutually exclusive by default. See the h, w, x, and y properties.
multiline password
No No
this.ui.textEdit.multiLine = "1";
None
page
No
None
print radiosInUnison
No No
this.relevant = "-print";
None
rect
Yes
You can get the height and width of a LiveCycle Designer ES form field by using the following reference syntax:
this.h; this.w;
Alternatively, you can retrieve the x and y coordinates of an object using the following reference syntax:
this.x; this.y; required
No
this.mandatory = "error";
or
this.validate.nullTest = "error"; textColor
No
this.fontColor
JavaScript in Acrobat
textSize textFont value
Comments See the size property. See the typeface property. See the rawValue property. Note: LiveCycle Designer ES fields have a value property; it is not the equivalent of the Acrobat value property.
No
DropDownList1.clearItems( );
The clearItems method only applies to Drop-down List and List Box objects in LiveCycle Designer ES.
No No No No No No
None None
DropDownList1.addItem( .....) if(CheckBox1.rawValue == 1)....
None None Not applicable for LiveCycle Designer ES forms. The setFocus method requires that the specified object have a unique name with respect to other objects on your form.
setFocus
Yes
xfa.host.setFocus ("TextField1.somExpression")
JavaScript in Acrobat
signatureSetSeedValue signatureSign signatureValidate search object method search.query("<your text>");
Comments
Yes
None
The .. (double period) FormCalc shortcut syntax allows you to search for objects within the XML Form Object Model.
Yes
None
14
Changing the background colors of fields, fillable areas, and subforms Hiding and showing objects Changing the visual properties of an object on the client Getting the current or previous value of a drop-down list Adjusting the height of a field at run time Setting a field as required at run time Calculating the field sums Highlighting fields in response to form filler interaction Resetting the values of the current subform Changing the presence of a form design object Using the properties of the instance manager to control subforms Using the methods of the instance manager to control subforms Using the instance manager to control subforms at run time
93
Note: To manipulate the background color of objects at run time, you must save your form as an Acrobat Dynamic XML Form file. To see this scripting example and others, visit the LiveCycle ES Developer Center at www.adobe.com/devnet/livecycle.
Scripting the subform and text field background colors
You set the subform and the text field background colors by using the fillColor method. For example, the following line is the script for the subform:
Subform1.fillColor = "17,136,255";
The following lines make up the script for the background color of the text fields:
Subform1.Name.fillColor = "102,179,255"; Subform1.Address.fillColor = "102,179,255"; Subform1.City.fillColor = "102,179,255"; Subform1.State.fillColor = "102,179,255"; Subform1.ZipCode.fillColor = "102,179,255"; Subform1.Country.fillColor = "102,179,255";
When setting the background color or the fillable area for each text field, your scripts must access properties that require a reference syntax expression that includes the number sign (#). Because JavaScript does not interpret the number sign (#) properly in reference syntax expressions, the script uses the resolveNode method to resolve the expression.
xfa.resolveNode("Subform1.Name.ui.#textEdit.border.fill.color").value = "153,204,255"; xfa.resolveNode("Subform1.Address.ui.#textEdit.border.fill.color").value = "153,204,255"; xfa.resolveNode("Subform1.City.ui.#textEdit.border.fill.color").value = "153,204,255"; xfa.resolveNode("Subform1.State.ui.#textEdit.border.fill.color").value = "153,204,255"; xfa.resolveNode("Subform1.ZipCode.ui.#textEdit.border.fill.color").value = "153,204,255"; xfa.resolveNode("Subform1.Country.ui.#textEdit.border.fill.color").value = "153,204,255"; Scripting the Clear All button
The script for the Clear All button uses the remerge method to remerge the form design and form data. In this case, the method effectively restores the fields, fillable areas, and subforms to their original state.
xfa.form.remerge();
The form filler can use the drop-down lists in the Presence Values area to show or hide objects. In the following diagram, the Address field is hidden and the form layout has adjusted accordingly. The Print Form button is also invisible.
Note: To hide and show objects at run time, you must save your form as an Acrobat Dynamic PDF Form file. To see this scripting example and others, visit the LiveCycle ES Developer Center www.adobe.com/devnet/livecycle.
Scripting the presence values for subforms
The script for the subform presence values uses a switch statement to handle the three presence options that a form filler can apply to the subform object:
switch(xfa.event.newText) { case 'Invisible': Subform1.presence = "invisible"; break; case 'Hidden (Exclude from Layout)': Subform1.presence = "hidden"; break; default: Subform1.presence = "visible"; break; }
The script for the text fields presence values requires two variables. The first variable stores the number of objects contained in Subform1:
var nSubLength = Subform1.nodes.length;
The second variable stores the name of the text field that the form filler selects in the Text Fields drop-down list:
var sSelectField = fieldList.rawValue;
The following script uses the replace method to remove all of the spaces from the name of the field stored in the sSelectField variable, which allows the value of the drop-down list to match the name of the object in the Hierarchy palette:
sSelectField = sSelectField.replace(' ', '');
This script uses a For loop to cycle through all of the objects contained in Subform1:
for (var nCount = 0; nCount < nSubLength; nCount++) {
If the current object in Subform1 is of type field and the current object has the same name as the object that the form filler selected, the following switch cases are performed:
if ((Subform1.nodes.item(nCount).className == "field") & (Subform1.nodes.item(nCount).name == sSelectField)) {
The following script uses a switch statement to handle the three presence values that a form filler can apply to text field objects:
switch(xfa.event.newText) { case 'Invisible': Subform1.nodes.item(nCount).presence = "invisible"; break; case 'Hidden (Exclude from Layout)': Subform1.nodes.item(nCount).presence = "hidden"; break; default: Subform1.nodes.item(nCount).presence = "visible"; break; } } } Scripting the presence values for buttons
The script for the buttons presence values requires two variables. This variable stores the number of objects contained in Subform1:
var nSubLength = Subform1.nodes.length;
This variable stores the name of the button that the form filler selects in the Buttons drop-down list:
var sSelectButton = buttonList.rawValue;
The following script uses the replace method to remove all of the spaces from the name of the button stored in the sSelectField variable, which allows the value of the drop-down list to match the name of the object in the Hierarchy palette:
sSelectButton = sSelecButton.replace(/\s/g, '');
This script uses a For loop to cycle through all of the objects contained in Subform1:
for (var nCount = 0; nCount < nSubLength; nCount++) {
If the current object in Subform1 is of type field and the current object has the same name as the object that the form filler selected, perform the following switch cases:
if ((Subform1.nodes.item(nCount).className == "field") & Subform1.nodes.item(nCount).name == sSelectButton)) {
This script uses a switch statement to handle the five presence values that a form filler can apply to button objects. Note: The relevant property indicates whether an object should appear when the form is printed.
switch(xfa.event.newText) { case 'Invisible': Subform1.nodes.item(nCount).presence break; case 'Hidden (Exclude from Layout)': Subform1.nodes.item(nCount).presence break; case 'Visible (but Don\'t Print)': Subform1.nodes.item(nCount).presence Subform1.nodes.item(nCount).relevant break; case 'Invisible (but Print Anyway)': Subform1.nodes.item(nCount).presence Subform1.nodes.item(nCount).relevant break; default: Subform1.nodes.item(nCount).presence break; } } } Scripting for resetting the drop-down lists
= "invisible";
= "hidden";
= "visible"; = "-print";
= "invisible"; = "+print";
= "visible";
Use the resetData method to reset all of the drop-down lists to their default values:
xfa.host.resetData();
Use the remerge method to remerge the form design and form data. In this case, the method effectively returns the objects in the Form Objects area to their original states:
xfa.form.remerge();
Note: To alter the visual properties of objects on the client, you must save your form as an Acrobat Dynamic PDF Form file. In this example, the check boxes do not have unique object names; therefore, LiveCycle Designer ES assigns an instance value to reference the object. The check box script uses an if-else statement to give the effect of selecting and deselecting. To see this scripting example and others, visit the LiveCycle ES Developer Center www.adobe.com/devnet/livecycle.
When the check box is selected, the field is moved according to the x and y settings. When the check box is deselected, the field is returned to its original location.
if (CheckBox1.rawValue == true) { TextField.x = "3.0in"; TextField.y = "3.5in"; } else { TextField.x = "1in"; TextField.y = "3in"; } Scripting for the Make the Field Wider check box
When the check box is selected, the field changes to 4 inches. When the check box is deselected, the field width changes to 2.5 inches.
if (CheckBox2.rawValue == true) TextField.w = "4in"; else TextField.w = "2.5in"; Scripting for the Make the Field Taller check box
When the check box is selected, the field height changes to 1.5 inches. When the check box is deselected, the field height changes to .5 inches.
if (CheckBox3.rawValue == true) TextField.h = "1.5in"; else TextField.h = "0.5in"; Scripting for the Change the Border Color of the Object check box
When the check box is selected, the field border changes to red. When the check box deselected, the field border changes to white.
if (CheckBox4.rawValue == true) TextField.border.edge.color.value = "255,0,0"; else TextField.border.edge.color.value = "255,255,255"; Scripting for the Change the Fill Color of the Fillable Area check box
When the check box is selected, the fillable area of the text field changes to green. When the check box is deselected, the fillable area of the text field changes to white.
if (CheckBox5.rawValue == true) { xfa.resolveNode("TextField.ui.#textEdit.border.fill.color").value = "0,255,0"; } else { xfa.resolveNode("TextField.ui.#textEdit.border.fill.color").value = "255,255,255"; }
Scripting for the Expand to Fit the Width of the Value check box
When the check box is selected, the fillable area of the text field adjusts to accommodate the value. When the check box is deselected, the fillable area of the text field does not adjust.
if (CheckBox6.rawValue == true) TextField.minW = "0.25in"; else TextField.maxW = "2.5in"; Scripting for the Make the Field Disappear check box
When the check box is selected, the field is hidden. When the check box is deselected, the field is visible.
if (CheckBox7.rawValue == true) TextField.presence = "hidden"; else TextField.presence = "visible"; Scripting for the Change the Font of the Value check box
When the check box is selected, the font of the value changes to Courier New. When the check box is deselected, the font of the value changes to Myriad Pro.
if (CheckBox8.rawValue == true) TextField.font.typeface = "Courier New"; else TextField.font.typeface = "Myriad Pro"; Scripting for the Change the Size of the Font check box
When the check box is selected, the font size changes to 14 pt. When the check box is deselected, the font size changes to 10 pt.
if (CheckBox9.rawValue == true) TextField.font.size = "14pt"; else TextField.font.size = "10pt"; Scripting for the Align Text Field Value Vertically check box
When the check box is selected, the text field value is aligned to the top. When the check box is deselected, the text field value is aligned to the middle.
if (CheckBox10.rawValue == true) TextField.para.vAlign = "top"; else TextField.para.vAlign = "middle"; Scripting for the Align Text Field Value Horizontally check box
When the check box is selected, the text field value is aligned to the center. When the check box is deselected, the text field value is aligned to the left.
if (CheckBox11.rawValue == true) TextField.para.hAlign = "center"; else TextField.para.hAlign = "left";
When the check box is selected, the value that is defined by using a script appears in the text field. When the check box is deselected, the default value (which is also defined by using a script) appears in the text field.
if (CheckBox12.rawValue == true) TextField.rawValue = "This is a value set using a script."; else TextField.rawValue = "This is a default value."; Scripting for the Change the Caption Text check box
When the check box is selected, the alternate caption text that is defined by using a script appears as the caption. When the check box is deselected, the default caption (which is also defined by using a script) appears in the text field.
if (CheckBox13.rawValue == true) xfa.resolveNode("TextField.caption.value.#text").value = "Alternate Caption:"; else xfa.resolveNode("TextField.caption.value.#text").value = "Caption:"; Scripting for the Change Field Border from 3D to Solid check box
When the check box is selected, the field border changes to a solid box. When the check box is deselected, the field border changes to 3D.
if (CheckBox14.rawValue == true) xfa.resolveNode("TextField.ui.#textEdit.border.edge").stroke = "solid"; else xfa.resolveNode("TextField.ui.#textEdit.border.edge").stroke = "lowered"; Scripting for the Clear All Check Boxes button
Use the resetData method to reset all of the check boxes to their default value (Off ).
xfa.host.resetData();
Use the remerge method to remerge the form design and form data. In this case, the method effectively returns the text field to its original state.
xfa.form.remerge();
list, the new value appears in the Current Value List and the previous value appears in the Previous Value 1 field.
Note: Each of the methods for obtaining the previous value of a drop-down list uses a different script. The Previous Value 1 text field is populated by a direct reference to the rawValue property of the drop-down list, whereas the Previous Value 2 text field is populated using the prevText property. For consistent results, it is recommended that you access the previous value by using the prevText property. To see this scripting example and others, visit the LiveCycle ES Developer Center at www.adobe.com/devnet/livecycle.
Scripting for populating the Current Value text field
Populate the value of the Current Value text field by using the newText property:
CurrentValue.rawValue = xfa.event.newText; Scripting for populating the Previous Value 1 text field
Populate the value of the Previous Value 1 text field by referencing the rawValue of the drop-down list:
PreviousValue1.rawValue = DropDownList.rawValue; Scripting for populating the Previous Value 2 text field
Populate the value of the Previous Value 2 text field by using the prevText property:
PreviousValue2.rawValue = xfa.event.prevText;
To see this scripting example and others, visit the LiveCycle ES Developer Center at www.adobe.com/devnet/livecycle.
Scripting for the Expand button
To see this scripting example and others, visit the LiveCycle ES Developer Center www.adobe.com/devnet/livecycle.
Scripting for the Set as Required button
To see this scripting example and others, visit the LiveCycle ES Developer Center at www.adobe.com/devnet/livecycle.
Scripting for calculating the sum of repeating fields in a form
To calculate the sum of repeating fields in a form, you add a calculate event to the Sum field:
var fields = xfa.resolveNodes("NumericField1[*]"); var total = 0; for (var i=0; i <= fields.length-1; i++) { total = total + fields.item(i).rawValue; } this.rawValue = total; Scripting for calculating the sum of repeating fields
Similarly, to calculate the sum of repeating fields, you add a calculate event to the Sum field:
var fields = xfa.resolveNodes("detail[*].NumericField1"); var total = 0; for (var i=0; i <= fields.length-1; i++) { total = total + fields.item(i).rawValue; } this.rawValue = total;
To calculate the sum of the fields on the page, you add a calculate event to the Sum field:
var fields = xfa.layout.pageContent(0 , "field", 0); var total = 0; for (var i=0; i <= fields.length-1; i++) { if (fields.item(i).name == "NumericField1") { total = total + fields.item(i).rawValue; } } this.rawValue = total;
To see this scripting example and others, visit the LiveCycle ES Developer Center at www.adobe.com/devnet/livecycle.
To add the blue border around the selected field, add the following scripts to each text field: For example, add an enter event to the Name field:
Name.border.edge.color.value = "0,0,255";
The following script, which is created for the Verify Data button, performs a series of checks to verify that the required fields contain data. In this case, each field is individually checked to verify that the value of the field is non-null or an empty string. If the value of the field is null or an empty string, an alert message appears indicating that data must be input into the field and the background color of the fillable area is changed to red. Use this variable to indicate whether a field does not contain data:
var iVar = 0; if ((Name.rawValue == null) || (Name.rawValue == "")) { xfa.host.messageBox("Please enter a value in the Name field.");
This script changes the color of the fillable area of the text field:
xfa.resolveNode("Name.ui.#textEdit.border.edge").stroke = "solid"; xfa.resolveNode("Name.ui.#textEdit.border.fill.color").value = "255,100,50"; // Set the variable to indicate that this field does not contain data. iVar = 1; } else { // Reset the fillable area of the text field. xfa.resolveNode("Name.ui.#textEdit.border.edge").stroke = "lowered"; xfa.resolveNode("Name.ui.#textEdit.border.fill.color").value = "255,255,255"; } if ((Address.rawValue == null) || (Address.rawValue == "")) { xfa.host.messageBox("Please enter a value in the Address field.");
This script changes the color of the fillable area of the text field:
xfa.resolveNode("Address.ui.#textEdit.border.edge").stroke = "solid"; xfa.resolveNode("Address.ui.#textEdit.border.fill.color").value = "255,100,50";
This script sets the variable to indicate that this field does not contain data:
iVar = 1; } else {
This script changes the color of the fillable area of the text field:
xfa.resolveNode("City.ui.#textEdit.border.edge").stroke = "solid"; xfa.resolveNode("City.ui.#textEdit.border.fill.color").value = "255,100,50";
This script sets the variable to indicate that this field does not contain data:
iVar = 1; } else {
This script changes the color of the fillable area of the text field:
xfa.resolveNode("State.ui.#textEdit.border.edge").stroke = "solid"; xfa.resolveNode("State.ui.#textEdit.border.fill.color").value = "255,100,50";
This script sets the variable to indicate that this field does not contain data:
iVar = 1; } else {
This script changes the color of the fillable area of the text field:
xfa.resolveNode("ZipCode.ui.#textEdit.border.edge").stroke = "solid"; xfa.resolveNode("ZipCode.ui.#textEdit.border.fill.color").value = "255,100,50";
This script sets the variable to indicate that this field does not contain data:
iVar = 1; } else {
This script changes the color of the fillable area of the text field:
xfa.resolveNode("Country.ui.#textEdit.border.edge").stroke = "solid"; xfa.resolveNode("Country.ui.#textEdit.border.fill.color").value = "255,100,50";
This script sets the variable to indicate that this field does not contain data.
iVar = 1; } else {
If all of the required fields contain data, the iVar variable is set to zero, and a confirmation message appears:
if (iVar == 0) { xfa.host.messageBox("Thank you for inputting your information."); }
To see this scripting example and others, visit the LiveCycle ES Developer Center www.adobe.com/devnet/livecycle.
Scripting for the values that appear in the left column
Type this script for the values appearing in the left column:
this.rawValue = this.parent.index + 1;
To reset the default values add a click event to the Clear button. You need a dynamic reference syntax expression because the detail is a repeating subform and must be reflected in the reference syntax expression. In this situation, it is easier to build the resetData parameters separately.
var f1 = this.parent.somExpression + ".TextField2" + ","; var f2 = f1 + this.parent.somExpression + ".DropDownList1" + ","; var f3 = f2 + this.parent.somExpression + ".NumericField1"; // ...and pass the variable as a parameter. xfa.host.resetData(f3);
JavaScript
ObjectName.presence = "visible";
JavaScript
ObjectName.presence = "visible"; ObjectName.relevant = "-print";
FormCalc
ObjectName.presence = "visible" ObjectName.relevant = "+print"
JavaScript
ObjectName.presence = "visible"; ObjectName.relevant = "+print";
Invisible
FormCalc
ObjectName.presence = "invisible"
JavaScript
ObjectName.presence = "invisible";
FormCalc
ObjectName.presence = "hidden"
JavaScript
ObjectName.presence = "hidden";
FormCalc
ObjectName.presence = "simplex"
JavaScript
ObjectName.presence = "simplex";
FormCalc
ObjectName.presence = "duplex"
JavaScript
ObjectName.presence = "duplex";
Scripting for the message box to output the value of the count property
The following script uses the messageBox method to output the value of the count property:
xfa.host.messageBox("The current number of Subform1 instances on the form is:" + properties.Subform1.instanceManager.count, "Instance Manager Properties",3);
You can also write this script by using the underscore (_) notation to reference the count property of the instance manager, as shown here:
xfa.host.messageBox("The current number of Subform1 instances on the form is: " + properties._Subform1.count, "Instance Manager Properties", 3);
The underscore (_) notation is especially important if no subform instances currently exist on the form.
Scripting for the message box to output the value of the max property
The following script uses the messageBox method to output the value of the max property:
xfa.host.messageBox("The maximum number of instances allowed for Subform1 is: " + properties.Subform1.instanceManager.max, "Instance Manager Properties", 3);
You can also write this script by using the underscore (_) notation to reference the max property of the instance manager, as shown here:
xfa.host.messageBox("The maximum number of instances allowed for Subform1 is: " + properties._Subform1.max, "Instance Manager Properties", 3);
Scripting for the message box to output the value of the min property
The following script uses the messageBox method to output the value of the min property:
xfa.host.messageBox("The minimum number of instances allowed for Subform1 is: " + properties.Subform1.instanceManager.min, "Instance Manager Properties", 3);
You can also write this script by using the underscore (_) notation to reference the min property of the instance manager, as shown here:
xfa.host.messageBox("The minimum number of instances allowed for Subform1 is: " + properties._Subform1.min, "Instance Manager Properties", 3); Scripting for the message box to output the name of the subform property
The following script uses the messageBox method to output the name of the subform property:
xfa.host.messageBox("The name of the subform using the instance manager name property is: " + properties.Subform1.instanceManager.name + ".\n\nNote: This value is different than the value returned by the name property for the Subform1 object." , "Instance Manager Properties", 3);
You can also write this script by using the underscore (_) notation to reference the name property of the instance manager, as shown here:
xfa.host.messageBox("The name of the subform using the instance manager name property is: " + properties._Subform1.name + ".\n\nNote: This value is different than the value returned by the name property for the Subform1 object." , "Instance Manager Properties", 3);
Note: The Move button reorders the first two Subform2 instances, and the Set button displays the maximum number of Subform2 instances. In both cases, you may need to add or remove subforms, or make changes to the data in the text fields to see the changes applied to the Subform2 instances.
Scripting to determine whether you added the maximum number of subforms to a form
The following script determines whether the supported maximum number of Subform2 instances exist on the form. If the maximum number exists, the script displays a message. Otherwise, a new Subform2 instance is added to the form.
if (methods.Subform2.instanceManager.count == methods.Subform2.instanceManager.max) { xfa.host.messageBox("You have reached the maximum number of items allowed.", "Instance Manager Methods", 1); } else { methods.Subform2.instanceManager.addInstance(1); xfa.form.recalculate(1);
} You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here:
if (methods._Subform2.count == methods._Subform1.max) { xfa.host.messageBox("You have reached the maximum number of items allowed.", "Instance Manager Methods", 1); } else { methods._Subform2.addInstance(1); xfa.form.recalculate(1); } Scripting to determine whether there are more subforms to remove on the form
The following script determines whether any Subform2 instances exist on the form. If none exist, the script displays a message indicating that no instances exist. If instances do exist, the script removes the first instance from the form.
if (methods.Subform2.instanceManager.count == 0) { xfa.host.messageBox("There are no subform instances to remove.", "Instance Manager Methods", 1); } else { methods.Subform2.instanceManager.removeInstance(0); xfa.form.recalculate(1); }
You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here:
if (methods._Subform2.count == 0) { xfa.host.messageBox("There are no subform instances to remove.", "Instance Manager Methods", 1); } else { methods._Subform2.removeInstance(0); xfa.form.recalculate(1); }
The following script forces four Subform2 instances to appear on the form regardless of how many instances currently exist:
methods.Subform2.instanceManager.setInstances(4);
You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here:
methods._Subform2.setInstances(4); Scripting to force the first and second subforms to switch locations on the form
The following script forces the first and second Subform2 instances to switch locations on the form.
methods.Subform2.instanceManager.moveInstance(0,1);
You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here.
methods._Subform2.moveInstance(0,1);
Tip: If no instances of a particular subform exist on your form, you must use the underscore (_) notation provided with each example below. For more information about using the underscore (_) notation, see LiveCycle Designer ES Help.
The following script determines whether the supported maximum number of Subform3 instances exist on the form. If the maximum number exist, the script displays a message. Otherwise, a new Subform3 instance is added to the form.
if (advanced.Subform3.instanceManager.count == advanced.Subform3.instanceManager.max) { xfa.host.messageBox("You have reached the maximum number of items allowed.","Combining Instance Manager Concepts", 1); } else { advanced.Subform3.instanceManager.addInstance(1); xfa.form.recalculate(1); }
You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here:
if (advanced._Subform3.count == advanced._Subform3.max) { xfa.host.messageBox("You have reached the maximum number of items allowed.", "Combining Instance Manager Concepts", 1); } else { advanced._Subform3.addInstance(1); xfa.form.recalculate(1); } Scripting the Remove a Subform button
The following script determines whether any Subform3 instances exist on the form. If none exist, the script displays a message indicating that no instances exist. If instances exist, the script removes the first instance from the form.
if (advanced.Subform3.instanceManager.count == 0) { xfa.host.messageBox("There are no subform instances to remove.", "Combining Instance Manager Concepts", 1); } else { advanced.Subform3.instanceManager.removeInstance(0); }
You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here:
if (advanced._Subform3.count == 0) { xfa.host.messageBox("There are no subform instances to remove.", "Combining Instance Manager Concepts", 1); } else { advanced._Subform3.removeInstance(0); }
The following if-else statement prevents the script from proceeding if the form currently contains the maximum number of Subform3 instances:
if (Subform3.instanceManager.count < Subform3.instanceManager.occur.max) { //oNewInstance stores an instance of Subform3 created by the addInstance() method. var oNewInstance = Subform3.instanceManager.addInstance(1); //nIndexFrom and nIndexTo store the before and after index values to use with the moveInstance() method. var nIndexFrom = oNewInstance.index; var nIndexTo = Subform3.index + 1;
In this case, when the script references the value for nIndexFrom, the new instance of Subform3 is added to the form in the position specified in the moveInstance method:
Subform3.instanceManager.moveInstance(nIndexFrom, nIndexTo); } else { xfa.host.messageBox("You have reached the maximum number of items allowed.", "Combining Instance Manager Concepts", 1); }
You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here:
if (_Subform3.count < _Subform3.occur.max) { var oNewInstance = _Subform3.addInstance(1); var nIndexFrom = oNewInstance.index; var nIndexTo = Subform3.index + 1; _Subform3.moveInstance(nIndexFrom, nIndexTo); } else { xfa.host.messageBox("You have reached the maximum number of items allowed.", "Combining Instance Manager Concepts", 1); } Scripting the Delete This Instance button
The following if-else statement prevents the script from proceeding if the form currently contains the minimum number of Subform3 instances.
if (Subform3.instanceManager.count > Subform3.instanceManager.occur.min) {
This script uses the removeInstance method to remove an instance of Subform3. Note: This script uses the value parent.parent.index to indicate the Subform3 instance to remove. The parent reference indicates the container of the object using the reference. In this case, using the reference parent.index would indicate the untitled subform that contains the Add Instance Below, Delete This Instance, Move Row Up, and Move Row Down buttons.
Subform3.instanceManager.removeInstance(parent.parent.index); } else { xfa.host.messageBox("You have reached the minimum number of items allowed.", "Combining Instance Manager Concepts", 1); }
You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here:
if (_Subform3.count > _Subform3.occur.min) { Subform3.removeInstance(Subform3.index); } else { xfa.host.messageBox("You have reached the minimum number of items allowed.", "Combining Instance Manager Concepts", 1); } Scripting the Move Row Up button
The following if-else statement prevents the script from proceeding if the instance of Subform3 appears as the first instance in the list:
if (Subform3.index != 0) { //nIndexFrom and nIndexTo store the before and after index values to use with the moveInstance method. var nIndexFrom = Subform3.index; var nIndexTo = Subform3.index - 1; Subform3.instanceManager.moveInstance(nIndexFrom, nIndexTo); } else { xfa.host.messageBox("The current item cannot be moved because it is the first instance in the list.", "Combining Instance Manager Concepts", 1); }
You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here:
if (Subform3.index != 0) { var nIndexFrom = Subform3.index; var nIndexTo = Subform3.index - 1; Subform3.moveInstance(nIndexFrom, nIndexTo); } else { xfa.host.messageBox("The current item can't be moved since it already is the first instance in the list.", "Combining Instance Manager Concepts", 1); }
The following if-else statement prevents the script from proceeding if the instance of Subform3 appears as the last instance in the list:
if ((nIndex + 1) < Subform3.instanceManager.count) { // nIndexFrom and nIndexTo store the before and after index values to use with the moveInstance() method. var nIndexFrom = nIndex; var nIndexTo = nIndex + 1; Subform3.instanceManager.moveInstance(nIndexFrom, nIndexTo); } else { xfa.host.messageBox("The current item cannot be moved because it is the last instance in the list.", "Combining Instance Manager Concepts", 1); }
You can also write this script by using the underscore (_) notation to reference the properties and methods of the instance manager, as shown here:
var nIndex = Subform3.index; if ((nIndex + 1) < Subform3.instanceManager.count) { var nIndexFrom = nIndex; var nIndexTo = nIndex + 1; _Subform3.moveInstance(nIndexFrom, nIndexTo); } else { xfa.host.messageBox("The current item can't be moved since it already is the last instance in the list.", "Combining Instance Manager Concepts", 1); }
Index
A
adding FormCalc functions to objects 50 JavaScript scripts to objects 54 script fragments 70 scripts to script objects 67 Adobe Acrobat converting forms containing scripts 79 JavaScript object model 79 Adobe LiveCycle Designer ES converting Acrobat forms to 79 scripting, moving from Acrobat 78 application events 29 Arabic characters, displaying 13 array referencing 65 default processing application, setting 13 scripting language, setting 12, 13 defining text variables 55 displaying international characters 13 Script Editor 12 docClose event 32 docReady event 33 drop-down lists, value of, obtaining 103
E
enter event 33 event model about 77 scripting properties and methods 77 events about 20, 26 application events 29 calculate (processing event) 30 change (interactive event) 31 click (interactive event) 32 docClose (application event) 32 docReady (application event) 33 enter (interactive event) 33 exit (interactive event) 34 form:ready (processing event) 34 full (interactive event) 35 indexChange (processing event) 35 initialize (processing event) 36 interactive 27 layout:ready (processing event) 36 mouseDown (interactive event) 37 mouseEnter (interactive event) 37 mouseExit (interactive events 38 mouseUp (interactive event) 38 postPrint (application event) 39 postSave (application event) 39 preOpen (interactive event) 40 prePrint (application event) 40 preSave (application event) 41 preSubmit (application event) 41 processing events 26 scripting, viewing 21 scripts associated with 20 types of 26 validate (processing event) 42 executing events 26 scripts in JavaScript Console 73 exit event 34 expressions, Acrobat-equivalent 76
B
basic calculations 51 built-in functions, FormCalc 49
C
calculate event 30 calculations about 9 about creating 16 adding object reference syntax to 20 attaching to objects 16 creating 18, 19 current object, referencing 62 debugging 14, 23, 71 event model properties and methods 77 referencing objects in 58, 60, 62 running 20, 23 testing 23 variables 56 change event 31 click event 32 colors, background, changing 94 comparing FormCalc and JavaScript 43 creating calculations and scripts 18, 19 script fragments 69 script objects 67
D
debugging about calculations and scripts 71 calculations and scripts 14, 23 enabling the JavaScript Debugger 72 executing JavaScript scripts 73 using the JavaScript Console 74 using the messageBox method 71
121
Index
122 prevent from disappearing 73
F
fields at run time, setting as required 105 background color, changing 94 height, adjusting at run time 105 highlighting 107 sums, calculating 106 form designs object naming conventions 16 objects, changing presence of 111 form:ready event 34 FormCalc about 17, 49 basic calculations 51 built-in functions 49 function syntax 50 functions 43 functions, adding to objects 50 reference syntax shortcuts 62 referencing objects 58, 60, 62 forms, converting from Acrobat to LiveCycle Designer ES 79 fragments. See script fragments 69 full event 35 function syntax, FormCalc 50
L
layout:ready event 36
M
messageBox method 71 mouseDown event 37 mouseEnter event 37 mouseExit event 38 mouseUp event 38 multiline view, Script Editor 11, 12
N
naming form design objects and variables 16 variables 55
O
Object palette script fragment properties 69 objects attaching calculations and scripts to 16 calculation and script support 10 making visible and invisible 111 naming conventions 16 referencing in calculations and scripts 58, 60, 62 showing and hiding 96 viewing attached scripts 21 visual properties, changing 100 order of events 26
H
Hebrew characters, displaying 13 hiding objects 96 host application 75
I
indexChange event 35 initialize event 36 initiating events 26 inserting script fragments 70 instance manager controlling subforms at run time 116 methods, controlling subforms using 114 properties, controlling subforms using 113 interactive events 27
P
postPrint event 39 postSave event 39 preOpen event 40 prePrint event 40 preSave event 41 presence property 111 preSubmit event 41 processing application, default 13 processing events 26 properties, visual, changing for objects 100
J
JavaScript about 17, 53 adding scripts to objects 54 enabling 72 functions 43 objects supported from Acrobat 80 referencing objects 58, 60, 62 using objects from Acrobat 79 JavaScript Console about 71 debugging 74 executing scripts in 73 JavaScript Debugger about 71 enabling for LiveCycle Designer ES 72
R
reference syntax about 58 adding to calculations and scripts 20 referencing object properties and values 58 referencing objects 60, 62 shortcuts for FormCalc 62 referencing script objects 68
S
Script Editor about 11
Index
123 JavaScript scripts 71 text variables See also variables defining 55 deleting 56 viewing definition 56 text, finding and replacing in XML Source tab and Script Editor 19 Thai characters, displaying 13 triggering events 26
U
unnamed objects, referencing in calculations and scripts 60
V
validate event 42 variables See also text variables about 55 in calculations and scripts 56 naming 55 naming conventions 16 Vietnamese characters, displaying 13
X
XML Form Object Model about 58 instance manager 113 XML Source tab, finding and replacing text in 19
T
testing calculations and scripts 23