Copy link to clipboard
Copied
Hi there. I'm trying to rename a radio button using JS by creating a new radiobutton field. There are 3 options layed out:
[ ] Option 1
[ ] Option 2
[ ] Option 3
I'm trying to get the coords for each option using f.rect; but it returns the same coords regardless of which option I have checked. Is there a way to do this?
When fields have the same name, they are essentially the same field. In a PDF, a field is really a virtual thing. It's a name with an associated value. What the user sees on the screen is called a Widget. So your radio button group is 1 field with 3 widgets. By default, this.getField("FieldName") returns the 1st widget. To get the coordinates of the other widgets the widget ID is appended to the FieldName.
So this.getField("FieldName.0") gets the first widget and this.getField("FieldName.1")
...Copy link to clipboard
Copied
When fields have the same name, they are essentially the same field. In a PDF, a field is really a virtual thing. It's a name with an associated value. What the user sees on the screen is called a Widget. So your radio button group is 1 field with 3 widgets. By default, this.getField("FieldName") returns the 1st widget. To get the coordinates of the other widgets the widget ID is appended to the FieldName.
So this.getField("FieldName.0") gets the first widget and this.getField("FieldName.1") gets the second widget, etc.
Copy link to clipboard
Copied
That worked! Would it have killed them to put that in the reference, LOL.
Copy link to clipboard
Copied
The information about widgets is available in the Acrobat Javascript Reference.
Copy link to clipboard
Copied
And there's even an example of this exact issue:
Copy link to clipboard
Copied
Is there a way to find out the widget number of a rb group in the console or elsewhere?
I didn't find anything in the 2021 documentation on p. 386-387 and p. 424. It only states that the the widget number is determined by creation order, regardless of tab order. I don't recall the order the fields were created. I also know that I appended rb group as well as added widgets after the fact.
The field navigation tab only shows export values. Is it assumed that the widget order and field navigation order is the same?
Copy link to clipboard
Copied
What do you mean by "the widget number of a rb group"? Do you mean the number of widgets?
If so, you can examine the length of the page array or the exportValues array. And yes, their order will match each other, as well as the widget index number within the group.
Copy link to clipboard
Copied
I mean the widget number/widget index number. The zero-based number after a period of each widget.
I've attached what I see in the field navigation tab. It only shows the export values.
How would I go about this in the console? I wasn't able to find anything in the SDK regarding exportValues except for setting up new radio buttons. I don't know what you mean by length of page array.
Copy link to clipboard
Copied
The first item in that list is index 0, the second is index 1, etc.
If you read the exportValues property of the field it should print it out in the right order.
Like this:
this.getField("card1").exportValues;
Copy link to clipboard
Copied
Thanks, I thought I tried that before I posted, but I must have written it singular or something (i.e. exportValue).