Skip to main content
jonathanm75257324
Known Participant
August 7, 2018
質問

Validate all Missing Fields (Not Required Fields)

  • August 7, 2018
  • 返信数 1.
  • 870 ビュー

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?

このトピックへの返信は締め切られました。

返信数 1

Inspiring
August 7, 2018

The same script should work, with a simple modification. Can you post what you've tried?

jonathanm75257324
Known Participant
August 8, 2018

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

}

Inspiring
August 8, 2018

Try changing this line:

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

To this:

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