check that all required fields are filled out

Explorer ,
Apr 12, 2018

Copy link to clipboard

Copied

I have a form with a lot of fields in it.  Some are required, some are not.  How do I write a script for a button that will check all the fields and alert the user if any remain to be filled out, or that the form is complete and they may sign off before submitting to their supervisor for review?

I found the following script in the forums.  This worked.  Thank you to user "Try 67"

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

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

788

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

check that all required fields are filled out

Explorer ,
Apr 12, 2018

Copy link to clipboard

Copied

I have a form with a lot of fields in it.  Some are required, some are not.  How do I write a script for a button that will check all the fields and alert the user if any remain to be filled out, or that the form is complete and they may sign off before submitting to their supervisor for review?

I found the following script in the forums.  This worked.  Thank you to user "Try 67"

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

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

789

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
Apr 12, 2018 0
Adobe Community Professional ,
Apr 12, 2018

Copy link to clipboard

Copied

If they are actually submitting the form using a submit button, then no script is necessary. You just set the fields to be required in the field properties and that's it.

If by "the form is complete and they may sign off before submitting to their supervisor for review" you mean that they just save the form and email it, then you'll need a script.

Which is it?

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...
Apr 12, 2018 0
Explorer ,
Apr 12, 2018

Copy link to clipboard

Copied

Currently it is just set up where they check for it to be complete, sign off that it is complete, and save the form.  The supervisor then opens the form, verifies correct information, and signs off the form (making it read only) then saves again.

I would also like to be able to, if possible, run a script when the supervisor signs off that saves the completed pdf to a specified location and sends the form data to an excel file in a specified location.

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...
Apr 12, 2018 0
Explorer ,
Apr 12, 2018

Copy link to clipboard

Copied

Is there a way to set it up to where the form would save to a file location on a local network when the form was submitted, then the supervisor could open from that location, verify correct information, sign off - locking the data on the form?

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...
Apr 12, 2018 0
Explorer ,
Apr 24, 2018

Copy link to clipboard

Copied

I found the following script in the forums.  This worked.  Thank you to user "Try 67"

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

}

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...
Apr 24, 2018 0
try67 LATEST
Most Valuable Participant ,
Apr 24, 2018

Copy link to clipboard

Copied

You're welcome!


I just recommend replacing this part:

if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off"))

With:

if (f.valueAsString==f.defaultValue)

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...
Apr 24, 2018 1