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

How to fill out empty fields automatically?

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.7K

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

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

            }

        }

    }

}

Votes

Translate

Translate
Community Expert ,
Nov 27, 2017 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.

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

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 27, 2017 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.";

            }

        }

    }

}

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 Beginner ,
Nov 27, 2017 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?  

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

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 ,
Mar 23, 2022 Mar 23, 2022

Copy link to clipboard

Copied

LATEST

Hi.  I have a form I am working on where I can put the default value as N/A but need it to automatically delete when completed by the user.  Can you help me with the auto deletion script?  

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 27, 2017 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.";

            }

        }

    }

}

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

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 27, 2017 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

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

Copy link to clipboard

Copied

Alright, thank you. I‘ll try it tomorrow  

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