Copy link to clipboard
Copied
Hello,
I'm creating a form that is a shipping slip template with four required fields. I added a print button that runs JavaScript and gives an error message if any required fields don't get filled out. However, if someone is not shipping out four items in that shipment, they won't need to field out the four required fields. So, I added a button that will hide the required fields if they aren't needed for that order. But even though they are hidden, when I click print, the error message still pops up for the required fields that are empty (but hidden).
Is there a way I can fix that? So, the hidden, required fields won't be enforced.
Here is the script I'm using for the print button:
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"));}
Use this code:
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.hidden && f.valueAsString==f.defaultValue) {
emptyFields.push(f.name);
}
}
if (emptyFields.length > 0) {
app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
} else this.print();
If you had a separate print command, remove it.
Copy link to clipboard
Copied
Use this code:
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.hidden && f.valueAsString==f.defaultValue) {
emptyFields.push(f.name);
}
}
if (emptyFields.length > 0) {
app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
} else this.print();
If you had a separate print command, remove it.
Copy link to clipboard
Copied
Thank you for the help! That solved the issue.