Skip to main content
MaksDad07
Inspiring
April 12, 2018
Answered

check that all required fields are filled out

  • April 12, 2018
  • 1 reply
  • 2774 views

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?

This topic has been closed for replies.
Correct answer MaksDad07

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

}

1 reply

Joel Geraci
Community Expert
Community Expert
April 12, 2018

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?

MaksDad07
MaksDad07Author
Inspiring
April 12, 2018

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.