Adobe Acrobat Pro Fillable Form Required Fields

New Here ,
Jul 15, 2022 Jul 15, 2022

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

TOPICS
General troubleshooting , How to , JavaScript , PDF forms

Views

39

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Adobe Community Professional , Jul 15, 2022 Jul 15, 2022

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.

Likes

Translate

Translate
Adobe Community Professional ,
Jul 15, 2022 Jul 15, 2022

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.

Likes

Translate

Translate

Report

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
New Here ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

LATEST

Thank you for the help! That solved the issue.

Likes

Translate

Translate

Report

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