Form validation for required fields - fields not always requierd
Copy link to clipboard
Copied
Hi all,
Full disclosure, I don't know how to write script and typically try to cobble together solutions based on what I am able to find from script that folks have already posted so go easy on me. I have a form and have custom validation script set up for a few fields where if one text field is not null another text field becomes a required field. The form has a signature field that is always required which sets all fields to read only after signature, I also have a submit button that attaches the pdf to an email. The issue I am running into is if one of the custom validation required fields is left blank the user is able to sign the form but not submit as the submit button has built in validation from adobe, but the form will no longer show which fields are required as they are read only.
I am thinking the best option to validate the form is to add a button which would check the form prior to signature, but I am not sure how the script should look since the fields that would need to be checked aren't always required fields. I am not seeing anything that would allow for a blanket way to just check the required fields. Would it make sense to remove the custom validation script from the individual fields and add one long script to the button or is there a better way?
Copy link to clipboard
Copied
Adjust the name of the signature field and of the submit button, and place this script as a Calculation script in only one field (any one of them):
var total = 0;
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if (oFld.type == "text" && oFld.required == true && oFld.value == oFld.defaultValue) {
total += 1;
}
}
if (total == 0) {
this.getField("SIGNATURE").display = display.visible;
this.getField("SUBMIT").display = display.visible;
}
else {
this.getField("SIGNATURE").display = display.hidden;
this.getField("SUBMIT").display = display.hidden;
}
Acrobate du PDF, InDesigner et Photoshoptographe

