I'm not a newb to JavaScript but this is my first foray into Acrobat Scripting.
What I'm trying to do is change a text field based on the value selected in a boBox.
Since I have many different boboxes with the same set of options, and many text fields that are supposed to be bound to those, I would prefer a document scope function that could be reused for all of those.
I'm not sure if this is possible but here's what I'm thinking...
Detect when a bo box is changed. On the change event submission, take the export value from that and make it the value for the related text field.
Here's the steps:
- capture bo box onmouseup event
- detect which bo box triggered the event
- match up the name of the bo box to its associated text field using an array listing
- use a getField() to fetch the text field
- set the text fields value to be the export value of the bo box
Any help with this would be appreciated. Especially good sources about Acrobat event triggers and how they work. I have been through a great deal of the API documentation and can't find anything on it.
I'm not a newb to JavaScript but this is my first foray into Acrobat Scripting.
What I'm trying to do is change a text field based on the value selected in a boBox.
Since I have many different boboxes with the same set of options, and many text fields that are supposed to be bound to those, I would prefer a document scope function that could be reused for all of those.
I'm not sure if this is possible but here's what I'm thinking...
Detect when a bo box is changed. On the change event submission, take the export value from that and make it the value for the related text field.
Here's the steps:
- capture bo box onmouseup event
- detect which bo box triggered the event
- match up the name of the bo box to its associated text field using an array listing
- use a getField() to fetch the text field
- set the text fields value to be the export value of the bo box
Any help with this would be appreciated. Especially good sources about Acrobat event triggers and how they work. I have been through a great deal of the API documentation and can't find anything on it.
Share Improve this question asked May 13, 2011 at 22:57 Evan PlaiceEvan Plaice 14.2k6 gold badges78 silver badges95 bronze badges 5- If you can use jQuery things will be pretty simple - so can you? – user447356 Commented May 13, 2011 at 23:07
- Nope. Acrobat scripting isn't the usual JavaScript. If it was, I wouldn't have this issue. Think of it as a bare bones JS interpreter with a different DOM (there are actually 3 different DOMs in PDFs). – Evan Plaice Commented May 13, 2011 at 23:16
-
so plain JavaScript with
document.getElementsByTagName
will work? – user447356 Commented May 14, 2011 at 7:39 - @Shadow No, in Acrobat it would actually be this.getField("fieldName") or doc.getField("fieldName"). But, that's not the issue I'm trying to address here. I'm asking if there is a way to subscribe to field events from document scope. If you take a look at the Javascript API for Acrobat you'll find that, while the language is the same, the architecture is much different from the standard HTML DOM/JS model. What I'm looking for is somebody who is experienced in Acrobat development who may be able to answer this. – Evan Plaice Commented May 16, 2011 at 15:46
- I see.. thought it was more close to the "ordinary" JavaScript sorry. Hope someone will e by! :) – user447356 Commented May 16, 2011 at 19:07
1 Answer
Reset to default 4Found it!
After exhaustive hours/days of Googling I finally found a solution that works.
The handler function needs to be bound to the 'Keystroke' event.
The handler function should contain:
if(!event.willCommit) {
this.getField('[field]').value = event.change;
}
Note: Where 'field' is the name of the field being updated and event.change is the value selected in the bobox.
To fetch the export value of the selection use the following:
if(!event.willCommit) {
this.getField('[field]').value = event.changeEx;
}
Apparently, 'Keystroke' is fired any time a UI element is interacted with. If you don't want it to execute when the document loads, be sure to bind the handler function to the event during the page load event.
Thoughts: AcroForms JS (Javascript for Acrobat) has a seriously broken event model. If you were to get the value of the bobox while using this even handler it would serve up a stale value. Not only does it take an obscure hack to make it work but there is little/no AcroForms JS munity to provide answers to hard questions like these.