Validate all Missing Fields (Not Required Fields)
Copy link to clipboard
Copied
I've found the correct JavaScript for validating required fields upon a document action (Print/Save/Close) with a popup prompt; but I am looking to get rid of the Red Boxes (as they are ugly) by either searching for all blank fields or changing the color of the red box. All fields within the form are required, and as a result the form becomes very clunky. Any suggestions?
Copy link to clipboard
Copied
The same script should work, with a simple modification. Can you post what you've tried?
Copy link to clipboard
Copied
Hi George,
I'm using the following script below that I found from a different thread- I did not want it to list every field that is missing so I changed it to read "Notice: there are required fields that are missing." That being said, every field on the form is required (with the exception of check boxes/radio boxes).
Please see the script here:
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"));
app.alert("Notice: there are required fields that are missing.\n");
}
Copy link to clipboard
Copied
Try changing this line:
if (f.type != "button" && f.required ) {
To this:
if (f.type != "button" && f.type != "checkbox" && f.type !== "radiobutton") {
Copy link to clipboard
Copied
In addition, you should also change this line:
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
To:
if (f.valueAsString==f.defaultValue) emptyFields.push(f.name);

