Identifying two separate fields with the same name

New Here ,
Mar 09, 2018

Copy link to clipboard

Copied

I have a pair of check-boxes with the same field name to simulate a radio button. I would like to select both fields separately in a javascript. I can see on the field tab that they are denoted by "Same_Name#1" and "Same_Name#2", I tried calling them such but with no luck.

Will appreciate any help.

Using Acrobat DC Pro

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can access the whole group using just its base-name, like this:

this.getField("Same_Name")

Or you could access individual widgets using a period followed by an index number, like this:

this.getField("Same_Name.0")

this.getField("Same_Name.1")

etc.

TOPICS
Acrobat SDK and JavaScript

Views

186

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

Identifying two separate fields with the same name

New Here ,
Mar 09, 2018

Copy link to clipboard

Copied

I have a pair of check-boxes with the same field name to simulate a radio button. I would like to select both fields separately in a javascript. I can see on the field tab that they are denoted by "Same_Name#1" and "Same_Name#2", I tried calling them such but with no luck.

Will appreciate any help.

Using Acrobat DC Pro

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can access the whole group using just its base-name, like this:

this.getField("Same_Name")

Or you could access individual widgets using a period followed by an index number, like this:

this.getField("Same_Name.0")

this.getField("Same_Name.1")

etc.

TOPICS
Acrobat SDK and JavaScript

Views

187

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
Mar 09, 2018 0
Adobe Community Professional ,
Mar 10, 2018

Copy link to clipboard

Copied

Are you looking for a JavaScript solution with Acrobat DC Pro?
Then you posted in the wrong forum. This one here is about InDesign Scripting.

For JavaScript with PDF see into this here:

JavaScript

Should a moderator move this thread to the linked forum?

Regards,
Uwe

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...
Mar 10, 2018 1
New Here ,
Mar 10, 2018

Copy link to clipboard

Copied

Is there a way I can move this myself? Or delete the post?

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...
Mar 10, 2018 0
Adobe Community Professional ,
Mar 11, 2018

Copy link to clipboard

Copied

Any checkbox must have an unique "Export value" (Properties : Options) to act as radio-buttons.

To select a checkbox you just have to set its value:

this.getField("checkbox").value = "Yes";

To deselect the checkboxes group:

this.getField("checkbox").value = "Off";

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...
Mar 11, 2018 1
Most Valuable Participant ,
Mar 11, 2018

Copy link to clipboard

Copied

You can access the whole group using just its base-name, like this:

this.getField("Same_Name")

Or you could access individual widgets using a period followed by an index number, like this:

this.getField("Same_Name.0")

this.getField("Same_Name.1")

etc.

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...
Mar 11, 2018 0
Adobe Community Professional ,
Mar 12, 2018

Copy link to clipboard

Copied

Hi try67 ,

I'm not so much into JavaScript for Acrobat.


What I wonder: Would method getField() accept a function where one could filter with e.g. a regular expression?

There is no plural in the name of the method, but it would return an array of fields with your first example? Amazing.


FWIW: I'm more into ExtendScript where we have the method Folder.getFiles() that is accepting a "mask" as argument that could be a function where one could filter files by name with e.g. a regular expression returning an array of filtered files.

Thanks,
Uwe

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...
Mar 12, 2018 0
Most Valuable Participant ,
Mar 12, 2018

Copy link to clipboard

Copied

No, getField only returns a single Field object.

However, if you use it to access the whole group then you could then use the Field object's getArray() function to access all of the widgets under that group. For example:

var fields = this.getField("Same_Name").getArray();

The "fields" variable will be an array of Field objects.

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...
Mar 12, 2018 1
Adobe Community Professional ,
Mar 12, 2018

Copy link to clipboard

Copied

Ah… Thank you for clarification!

Best,
Uwe

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...
Mar 12, 2018 0