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

New Here ,
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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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();");

    }

}

TOPICS
Acrobat SDK and JavaScript

Views

201

Likes

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

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

New Here ,
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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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();");

    }

}

TOPICS
Acrobat SDK and JavaScript

Views

202

Likes

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
Aug 16, 2017 0
Most Valuable Participant ,
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();");

    }

}

Likes

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
Reply
Loading...
Aug 16, 2017 0
Herubu LATEST
New Here ,
Aug 16, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Aug 16, 2017 0