Empty fields notification script on a PDF form

Community Beginner ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Hi everyone,

I have built a PDF form and I need to put a control script on the Print button so that it checks empty fields right before printing the form.

Pretty easy right? Not exactly...

I have found this nice post from user try67​ who proposed a very cool script Re: Check to see if any field is empty 

var emptyFields = [];

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

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

     if (f.type!="button" && f.required ) {

          if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

     }

}

if (emptyFields.length>0) {

     app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));

}

The thing is I need to run the control only on three specific fields of the form, not all of them. I have no idea on how to put this as a script.

Could somebody help me with that?

Thank you in advance.

Xavier

TOPICS
PDF forms

Views

452

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
community guidelines

correct answers 1 Correct Answer

Most Valuable Participant , Aug 08, 2018 Aug 08, 2018
Use this code (adjust the field names in the first line, of course):var fields = ["Field1", "Field2", "Field3"];var emptyFields = [];for (var i=0; i<fields.length; i++) {    var f = this.getField(fields);    if (f.valueAsString==f.defaultValue) {        emptyFields.push(f.name);    }}if (emptyFields.length>0) {    app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));} else this.print();

Likes

Translate

Translate
Most Valuable Participant ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Use this code (adjust the field names in the first line, of course):

var fields = ["Field1", "Field2", "Field3"];

var emptyFields = [];

for (var i=0; i<fields.length; i++) {

    var f = this.getField(fields);

    if (f.valueAsString==f.defaultValue) {

        emptyFields.push(f.name);

    }

}

if (emptyFields.length>0) {

    app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));

} else this.print();

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
community guidelines
Community Beginner ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Works perfectly! Thanks mate!

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
community guidelines
New Here ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

LATEST

hello everyone. I have created a pdf form, and i needed a button for the user to attach files to it (it is an application form). Got the script for it but now i have another problem: i need those fields to be required. In short: i need a button tthat attaches the person's file ( like her/his resume) and also be a required field, meaning, if there is no attachment, the form can not be sent. Anyone with an idea to help me? This is what I have been trying for the last four hours and got nowhere: 

1- tried to create a text button that can be set as required, but even though the script works, form doesnt understand that the button doesnt need to be filled with text.

2-tried to create a checkbox and link it with the field so when file is attached, checkbox is filled - no success... maybe this could be a way but i have no idea how to execute it

3- tried to use the plain button and add a script for making it required but couldnt find a script that works...

So please!! help me

 

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
community guidelines