Skip to main content
Fango24
Participating Frequently
Nov 27, 2017 9:03 AM UTC
Answered

How to fill out empty fields automatically?

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

This topic is closed to new replies. Start a new post to keep the conversation going.
JR Boulay
JR BoulayCorrect answer
Community Expert
Nov 27, 2017 1:47 PM UTC

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.";

            }

        }

    }

}

Acrobate du PDF, InDesigner et Photoshopographe

10 replies

JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
Nov 27, 2017 1:47 PM UTC

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.";

            }

        }

    }

}

Translate
Acrobate du PDF, InDesigner et Photoshopographe
Fango24
Fango24Author
Participating Frequently
Nov 27, 2017 2:44 PM UTC

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 ..

Translate
Thom Parker
Community Expert
Community Expert
Nov 27, 2017 5:59 PM UTC

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

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
JR Boulay
Community Expert
Community Expert
Nov 27, 2017 9:59 AM UTC

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.

Translate
Acrobate du PDF, InDesigner et Photoshopographe
Fango24
Fango24Author
Participating Frequently
Nov 27, 2017 10:20 AM UTC

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

Translate
JR Boulay
Community Expert
Community Expert
Nov 27, 2017 10:52 AM UTC

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.";

            }

        }

    }

}

Translate
Acrobate du PDF, InDesigner et Photoshopographe