How to fill out empty fields automatically?

Community Beginner ,
Nov 27, 2017

Copy link to clipboard

Copied

Hi all,

I'm creating a pdf right now which has to be filled out by our customers.

Due to Audit restrictions every field has to contain a valid value. - if nothing is entered the field should display "n.a.".

My code right now:

event.rc = true;

if (event.value==""|| event.value ==""||event.value==0)

{

    event.value="n.a."

}

Problem is: It's valid only for one field and triggered by selecting the cell. - I'm searching for something like a Loop which checks all empty cells after finishing the editing.. (at saving, or signing digitally)

Many thanks in advance, I appreciate it

kindly regards Fango

Adobe Community Professional
Correct answer by JR Boulay | Adobe Community Professional

Oops!

But as I wrote: not tested…

This one was tested:

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

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

    if (f != null) {

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

            if ((f.value == "") || (f.value == " ") || (f.value == 0) || (f.value == null)) {

                f.value = "n.a.";

            }

        }

    }

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

300

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

How to fill out empty fields automatically?

Community Beginner ,
Nov 27, 2017

Copy link to clipboard

Copied

Hi all,

I'm creating a pdf right now which has to be filled out by our customers.

Due to Audit restrictions every field has to contain a valid value. - if nothing is entered the field should display "n.a.".

My code right now:

event.rc = true;

if (event.value==""|| event.value ==""||event.value==0)

{

    event.value="n.a."

}

Problem is: It's valid only for one field and triggered by selecting the cell. - I'm searching for something like a Loop which checks all empty cells after finishing the editing.. (at saving, or signing digitally)

Many thanks in advance, I appreciate it

kindly regards Fango

Adobe Community Professional
Correct answer by JR Boulay | Adobe Community Professional

Oops!

But as I wrote: not tested…

This one was tested:

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

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

    if (f != null) {

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

            if ((f.value == "") || (f.value == " ") || (f.value == 0) || (f.value == null)) {

                f.value = "n.a.";

            }

        }

    }

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

301

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
Nov 27, 2017 0
Adobe Community Professional ,
Nov 27, 2017

Copy link to clipboard

Copied

Can't you place the "n.a" as the default value?

And then use a script to automatically delete the default text when the field get the focus?

It would be easier.

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...
Nov 27, 2017 1
Community Beginner ,
Nov 27, 2017

Copy link to clipboard

Copied

Hi JR_Boulay,

I have already thought of that, but it would be much better-looking/ more professional the other way around.

Setting the default value to "n.a." is my stopgap

Thank you & regards

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...
Nov 27, 2017 0
Adobe Community Professional ,
Nov 27, 2017

Copy link to clipboard

Copied

You can try this script (not tested):

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

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

    if (f != null) {

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

            if ((f.value == "") || (f.value == " ") || (f.value == 0) || (f.value == null)) {

                event.value = "n.a.";

            }

        }

    }

}

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...
Nov 27, 2017 1
Community Beginner ,
Nov 27, 2017

Copy link to clipboard

Copied

if ((f.value == "") || (f.value == " ") || (f.value == 0) || (f.value == null))*) - had to add this bracket, but unfortunatly it only fills the selected cell. - is there something like a global console for the whole pdf?  

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...
Nov 27, 2017 0
Community Beginner ,
Nov 27, 2017

Copy link to clipboard

Copied

"Can't you place the "n.a" as the default value?

And then use a script to automatically delete the default text when the field get the focus?"

Unless somebody has another solution, i think i will go with this way. - May I ask you to Show me the code?

Many thanks in advance

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...
Nov 27, 2017 0
Adobe Community Professional ,
Nov 27, 2017

Copy link to clipboard

Copied

Oops!

But as I wrote: not tested…

This one was tested:

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

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

    if (f != null) {

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

            if ((f.value == "") || (f.value == " ") || (f.value == 0) || (f.value == null)) {

                f.value = "n.a.";

            }

        }

    }

}

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...
Nov 27, 2017 2
Community Beginner ,
Nov 27, 2017

Copy link to clipboard

Copied

That's exactly what i needed THANK you!

One small Problem still occurs:

If i enter a value within the "triggercell" i get a note, that the Format of the date is wrong (another cell within the doc), which is correct due to the fact, that i didn't insert one. - After that approx. the half of the boxes are filled with [n.a.] - If i now change the value of the triggerbox again, the error occurs another time, but now the rest gets filled out..

Do you have an idea why?

Thank you very much for your help so far ..

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...
Nov 27, 2017 0
Adobe Community Professional ,
Nov 27, 2017

Copy link to clipboard

Copied

When formatting is selected for a text field, Acrobat inserts JavaScript into the validate, format, and keystroke event scripts. It is this code that is causing the problem. Either Remove the formatting altogether, or remove the validation scripts from the date fields with this code

this.getField("DateField").setAction("Validate","");

This retains the date formatting, but removes validation.

Another option is to replace the Format Event scripts in all text fields with code to display n.a..  Then you don't need to test all the fields after  the form is filled. All fields correctly display a value all the time.

Use the same loop JR presented above to run this code

f.setAction("Format","if(/^\s*$/.test(event.value)) event.value = 'n.a.'; ");

Values set in the Format event do change the true value of the field, they only modify what is displayed in the field. So this is a great place to set the "n.a." display

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...
Nov 27, 2017 3
Fango24 LATEST
Community Beginner ,
Nov 27, 2017

Copy link to clipboard

Copied

Alright, thank you. I‘ll try it tomorrow  

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...
Nov 27, 2017 0