Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guest
Dec 29, 2016 Dec 29, 2016

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

TOPICS
Acrobat SDK and JavaScript
557
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2016 Dec 29, 2016

What is the reason for the first if ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 29, 2016 Dec 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2016 Dec 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 29, 2016 Dec 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2016 Dec 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");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 30, 2016 Dec 30, 2016

Hey thank you for that Karl. It did look like it worked the first time I ran it, but after that it's still not validating the radio buttons and I tried it on a few different forms. Sorry about that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 30, 2016 Dec 30, 2016
LATEST

If it worked once, we should be able to make it work again

Are you getting any error messages in the JavaScript console?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines