Copy link to clipboard
Copied
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");
Copy link to clipboard
Copied
What is the reason for the first if ?
Copy link to clipboard
Copied
The first if statement if for if I have any required fields that are dependent on another field and that field is invisible.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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");
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
If it worked once, we should be able to make it work again
Are you getting any error messages in the JavaScript console?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now