Skip to main content
December 29, 2016
Question

My checkboxes aren't being validated with script even though they are required.

  • December 29, 2016
  • 2 replies
  • 643 views

Good morning I am using the script inserted below. And every time I go to save my form with the check boxes it doesn't validate them saying they aren't answered even when required. I'd appreciate any help that can be given.

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

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

f.strokeColor = color.red;   //Highlights the required fields in red

emptyFields.push(f.name);
    }
}

if (emptyFields.length>0) {
     app.alert("You must fill in the following fields:\n" + emptyFields.join("\n"));
}

else app.execMenuItem("SaveAs");

This topic has been closed for replies.

2 replies

Karl Heinz  Kremer
Community Expert
December 29, 2016

There is a closing "}" missing in your script. The second "if" statement in line 5 is redundant: The first "if" statement already checks for the two conditions you are checking in line 5 again.

December 29, 2016

Thank you I did get rid of that second if statement and I keep trying to add a closing bracket but every time I do adobe doesn't seem to like that I'm adding it to there. And even fixing up that if statement it doesn't look like it helped. My radio buttons still are not being read by the script.

Karl Heinz  Kremer
Community Expert
December 29, 2016

After taking another look at your script, I think you are trying to modify a script from an old post here on this site (Check to see if any field is empty ). Try this:

var emptyFields = [];

for (var i = 0; i < this.numFields; i++) {

  var f = this.getField(this.getNthFieldName(i));

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

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

       f.strokeColor = color.red; //Highlights the required fields in red

       emptyFields.push(f.name);

     }

  }

}

if (emptyFields.length > 0) {

  app.alert("You must fill in the following fields:\n" + emptyFields.join("\n"));

} else {

  app.execMenuItem("SaveAs");

}

Bernd Alheit
Community Expert
December 29, 2016

What is the reason for the first if ?

December 29, 2016

The first if statement if for if I have any required fields that are dependent on another field and that field is invisible.