• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Use setAction without overwriting existing js

Explorer ,
Nov 25, 2017 Nov 25, 2017

Copy link to clipboard

Copied

I'm using the setAction to enter js for specific fields (see example below) I already have On Blur actions that exist for some of these fields that I do not wish to overwrite.... how do I add to an existing On Blur without overwriting?

var reqFields = new Array("Text1", "Text2");

for (i = 0; i < reqFields.length; i++) {
  this.getField(reqFields).setAction("OnBlur","test();");
}

TOPICS
Acrobat SDK and JavaScript , Windows

Views

371

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
community guidelines
Community Expert ,
Nov 25, 2017 Nov 25, 2017

Copy link to clipboard

Copied

Not possible.

Votes

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
community guidelines
Community Expert ,
Nov 25, 2017 Nov 25, 2017

Copy link to clipboard

Copied

Try is correct that when you overwrite an event script, it overwrites it. In addition to this, the event scripts can't be read. So to do this you would have to keep a copy of the original code in each script that will be overwritten, then build the final script from this.

However, setting event scripts is a development activity.  This is not the type of thing you have in a working document. It you are trying to use "field.setAction()" to modify fields at run time, then you should find a different way accomplish your goal. 

For example, include the complete code set into the event script, then use "if" statements to control which bits run.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Expert ,
Nov 25, 2017 Nov 25, 2017

Copy link to clipboard

Copied

This is why you never... never... never... put blocks of code in an action. Only put calls to functions into the actions tabs. Create a document level script that loads the functions when the document loads. That way you can easily edit what the events do without editing the code in the events themselves.

Then you can do fun stuff like...

this.getField("myField").setAction("doThis(event); thenThat(event);thenSomethingElse(event)");

... to chain together the functions that you need for that field event.

J-

Votes

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
community guidelines
Explorer ,
Nov 25, 2017 Nov 25, 2017

Copy link to clipboard

Copied

LATEST

Thanks, guys!  This document is in the re-development stage... I wasn't going to include this script in the final version of the user doc, I will use it only to add the same script to several fields, and this is the quickest and simplest way (as far as I know) to do it.

I knew that it was possible to manually add more than one On-Blur trigger event to a field, so I was wondering if there was a way of replicating this with setAction or some other similar scripting method.

My doc has approx. 25-30 fields that require the new On-Blur script (call to a doc level function), but there are approx. 5-8 fields with existing On-Blur triggers (call to other doc level functions) that I need to retain in addition to the new On-Blur function call.

I thought I would check here first before I proceeded with the process...

Votes

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
community guidelines