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

adding a function to all fields in a document (blur and focus)

New Here ,
Aug 16, 2017 Aug 16, 2017

Copy link to clipboard

Copied

Hi,

I've got a simple function that I have added to the 'DocumentJavascripts' in Acrobat in order to change the style of a field.  I know that for a single field, I can use the 'blur' and 'focus' triggers to run it.

But seeing as I need to apply this function to most of the fields in the PDF, is there an easier way of doing this?   Is there a document wide event listener that would work? 

I don't think this is important, but just in case the function I'm using is:

function Blurfield()

{

    V=this.getField(event.targetName);

    if (V.value.length==0)

    {

        V.borderStyle = border.s;

        V.fillColor = color.transparent;

        V.strokeColor = color.transparent;

    }

}

Many Thanks,

Herb

TOPICS
Acrobat SDK and JavaScript

Views

487

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

correct answers 1 Correct answer

Community Expert , Aug 16, 2017 Aug 16, 2017

There's no "global event listener", but you can use a simple script to do it. I assume you want to apply it to text fields, right?

If so, you can use this code from the JS Console to do it:

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (f.type=="text") {

        f.setAction("OnBlur", "Blurfield();");

    }

}

Votes

Translate

Translate
Community Expert ,
Aug 16, 2017 Aug 16, 2017

Copy link to clipboard

Copied

There's no "global event listener", but you can use a simple script to do it. I assume you want to apply it to text fields, right?

If so, you can use this code from the JS Console to do it:

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (f.type=="text") {

        f.setAction("OnBlur", "Blurfield();");

    }

}

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
New Here ,
Aug 16, 2017 Aug 16, 2017

Copy link to clipboard

Copied

LATEST

Thanks for that.  I was hoping there was a global event listener that would just resolve it easily, but I guess not.

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