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"));
}
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"));
}
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?
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.
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?
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"));
}
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)