Copy link to clipboard
Copied
I am creating a form with three checkboxes and several form fields. If the first two boxes are checked, the user needs to complete certain sections of the form before they can print. If the third box is checked, they only need to print the form and do not need to continue filling out the form. I added a print button at the bottom to run a script that if the required fields do not have data, the form will not print. But, how do I eliminate this warning if the user checks box #3? I've tried hiding the fields but I still receive the warning that I need to fill out the required fields even if they are hidden.
This is the script I am using from Try67, which works great for warning the user to fill in the required fields:
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null || f.type=="button") continue;
if (f.required && f.valueAsString==f.defaultValue) {
f.strokeColor = color.red; //Highlights the required fields with red outline
emptyFields.push(f.name);
} else f.strokeColor = color.gray; //Highlights the filled in fields with gray outline
}
if (emptyFields.length>0) {
app.alert("WAIT! You must fill in all of the required fields before printing this form");
} else this.print();
Thanks!
You can do it either in this code (not recommended) or via the MouseUp event of the check-box, which will change the required property of the fields, based on its new value (a better approach).
The basic code to do that would be this (as the MouseUp event of the check-box field):
this.getField("Name of other field").required = (event.target.value!="3");
Copy link to clipboard
Copied
You can do it either in this code (not recommended) or via the MouseUp event of the check-box, which will change the required property of the fields, based on its new value (a better approach).
The basic code to do that would be this (as the MouseUp event of the check-box field):
this.getField("Name of other field").required = (event.target.value!="3");
Copy link to clipboard
Copied
Thank you so much! To simplify things, I changed all of the required fields to "Required.Name" and so on. Then I only had to enter "Required" into the name field in the code. Worked just like I needed it to!