How to reference repeated text fields separately in javascript?

Jan 14, 2019

Copy link to clipboard

Copied

So let's say I have multiple instances of a text field, three in this case, all titled "Insert Date".

I can see when I'm in the "Prepare Form" page, that the fields have number identifiers on them once there is more than one of the same name

i.e.

Insert Date#0

Insert Date#1

Insert Date#2

I'm running some javascript script to set the font size of the field in question. I loop through all fields and set an if statement for fields named like the ones above:

loop

{

getname // works as it should call this cFieldName

getfield of getname  // works as it should call this oField

if (cFieldName == "Insert Date#0"){oField.textSize = 10;}

}

Unfortunately this sets the text size to 10 for all 3 fields, not just the specific one (Insert Date#0). It seems I'm not actually referencing that individual field. I absolutely need the field name to be the same. What can I do to achieve this?

TOPICS
Acrobat SDK and JavaScript, Windows

Views

95

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How to reference repeated text fields separately in javascript?

Jan 14, 2019

Copy link to clipboard

Copied

So let's say I have multiple instances of a text field, three in this case, all titled "Insert Date".

I can see when I'm in the "Prepare Form" page, that the fields have number identifiers on them once there is more than one of the same name

i.e.

Insert Date#0

Insert Date#1

Insert Date#2

I'm running some javascript script to set the font size of the field in question. I loop through all fields and set an if statement for fields named like the ones above:

loop

{

getname // works as it should call this cFieldName

getfield of getname  // works as it should call this oField

if (cFieldName == "Insert Date#0"){oField.textSize = 10;}

}

Unfortunately this sets the text size to 10 for all 3 fields, not just the specific one (Insert Date#0). It seems I'm not actually referencing that individual field. I absolutely need the field name to be the same. What can I do to achieve this?

TOPICS
Acrobat SDK and JavaScript, Windows

Views

96

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 14, 2019 0
Jan 14, 2019

Copy link to clipboard

Copied

So form fields on a PDF are really two different things, the field and the widget. The field you see on a page is a field widget. It is the physical representation of the form field, which is an abstract concept. Every widget on the page that has the same name is really just a representation of the same field. The # you see in the Forms edit display is widget index.

Following this concept there are separate field and widget properties. In general. Field properties are anything associated with the field value, such as calculation event. All fields share the same calculation script. where as Widget properties are about the physical appearance of the particular widget, such as it's location and color.

So you can do this, but you have to get the widget naming correct, and you can only set separate Widget properties.

For example:

this.getField("Date.0")

Use the dot notation.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2019 1
Jan 14, 2019

Copy link to clipboard

Copied

I see. So is it that there widgets are children of fields? If I'm looping through the fields and I hit the one I want with an if, would I then loop through the widgets? How would that be done?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2019 0
Jan 14, 2019

Copy link to clipboard

Copied

The widgets can look like children because of the access naming, so go with that if it helps. But there is no child array or length attribute. The only way to find all the widgets is to loop starting with an index of 0 and keep going until "getField" returns null.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2019 0