Highlighted

Prevent printing before filling out required fields

Community Beginner ,
Nov 13, 2020

Copy link to clipboard

Copied

Hello,
for a form i added a print button, on it is a javascript. Only when I click on the button I get the error message that several required fields have to be filled in, but the printing process starts anyway.
What I have wrong with the code?

 

 

 s1.png

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("Bitte füllen Sie noch folgende/s Pflichtfeld/er aus, bevor Sie das Formular drucken können:\n" + emptyFields.join("\n"));

}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You have to do it all in your code. Remove the separate print command and add this to the end of your code:

 

else this.print();

TOPICS
PDF forms

Views

18

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

Prevent printing before filling out required fields

Community Beginner ,
Nov 13, 2020

Copy link to clipboard

Copied

Hello,
for a form i added a print button, on it is a javascript. Only when I click on the button I get the error message that several required fields have to be filled in, but the printing process starts anyway.
What I have wrong with the code?

 

 

 s1.png

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("Bitte füllen Sie noch folgende/s Pflichtfeld/er aus, bevor Sie das Formular drucken können:\n" + emptyFields.join("\n"));

}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You have to do it all in your code. Remove the separate print command and add this to the end of your code:

 

else this.print();

TOPICS
PDF forms

Views

19

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
Nov 13, 2020 0
Most Valuable Participant ,
Nov 13, 2020

Copy link to clipboard

Copied

You have to do it all in your code. Remove the separate print command and add this to the end of your code:

 

else this.print();

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
Reply
Loading...
Nov 13, 2020 1