根据组合框选择设置字段
我不是 JavaScript 新手,但这是我第一次尝试 Acrobat 脚本。
我想做的是根据组合框中选择的值更改文本字段。
由于我有许多具有相同选项集的不同组合框,以及许多应该绑定到这些选项的文本字段,因此我更喜欢可以对所有这些选项重用的文档范围函数。
我不确定这是否可能,但这就是我的想法......
检测组合框何时更改。在提交更改事件时,从中获取导出值并将其设为相关文本字段的值。
步骤如下:
- 捕获组合框 onmouseup 事件
- 检测哪个组合框触发了该事件
- 使用数组列表将组合框的名称与其关联的文本字段相匹配
- 使用 getField() 获取文本字段
- 将文本字段值设置为组合框的导出值
如有任何帮助,我们将不胜感激。关于 Acrobat 事件触发器及其工作原理的特别好的资源。我查阅了大量的 API 文档,但没有找到任何内容。
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 comboBox.
Since I have many different comboboxes 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 combo 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 combo box onmouseup event
- detect which combo box triggered the event
- match up the name of the combo 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 combo 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了!
经过数小时/数天的谷歌搜索后,我终于找到了一个可行的解决方案。
处理函数需要绑定到“按键”事件。
处理函数应包含:
注意:其中“field”是正在更新的字段的名称,event.change 是在组合框中选择的值。
要使用以下命令获取所选内容的导出值:
显然,只要与 UI 元素交互,就会触发“按键”。如果您不希望它在文档加载时执行,请确保在页面加载事件期间将处理函数绑定到该事件。
想法:AcroForms JS(Acrobat 的 Javascript)的事件模型严重损坏。如果您要在使用此偶数处理程序时获取组合框的值,它将提供一个过时的值。不仅需要一些不起眼的 hack 才能使其工作,而且很少/没有 AcroForms JS 社区来提供此类难题的答案。
Found 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:
Note: Where 'field' is the name of the field being updated and event.change is the value selected in the combobox.
To fetch the export value of the selection use the following:
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 combobox 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 community to provide answers to hard questions like these.