Using Acrobat JavaScript in Forms
Forms Essentials
6
Setting the Hierarchy of Form Fields
The hierarchy of form fields is determined according to a naming strategy that uses "dot"
notation. For example, suppose you have 4 radio buttons that all belong to the same group.
The group could be named
myGroup
. The 4 radio buttons would then be named
myGroup.0
,
myGroup.1
,
myGroup.2
, and
myGroup.3
. The convenience of this
naming system becomes most apparent when you decide that all members of the group
should have the same property characteristics. For example, to set the glyph style of all 4
radio buttons, you can do this with one line of code as shown below:
var f = this.getField("myGroup");
f.style = style.ch; // glyph style for all radio buttons
This notation is certainly more convenient than typing in 4 nearly identical lines of code.
Suppose that you have 3 different groups, each of which has several radio buttons. You can
extend the hierarchical naming to this situation as well. Suppose that you would like to be
able to assign common property values to all 3 groups. To do this, you could create a parent
name for all the groups, such as
mySet
. The 3 groups would be named
mySet.0
,
mySet.1
, and
mySet.2
. Suppose the first group,
mySet.0
, has 2 radio buttons in it.
They would be named
mySet.0.0
and
mySet.0.1
. To set the glyph style for all 3 groups
of radio buttons, you can do this, again, with just a single line of code as shown below:
var f = this.getField("mySet");
f.style = style.ch; // glyph style for all 3 groups
You can also differentiate the groups within the hierarchy. Suppose you would like to
designate a yellow background color for the third set. You could do so with the following
statements:
var f = this.getField("mySet.2");
f.fillColor = color.yellow; // affects only the 3rd group
Creating Forms From Scratch
Positioning Form Form Fields
Remember that form field positioning takes place in
Rotated User Space,
in which the origin
of a page is located at the bottom left corner. This differs from
Info Space
and may require
that you occasionally perform transformations.
For example, suppose that you use the
Info
panel to obtain the coordinates of a given
rectangle. Use the
doc
object’s
getPageBox
method to obtain the coordinates in Rotated
User Space for the page, and then subtract the Info Space y-coordinates from the page
height provided by the
getPageBox
method.
Acrobat JavaScript Scripting Guide
103