Skip to main content
individualistic_Swirl5D2F
Known Participant
November 13, 2020
Answered

Prevent printing before filling out required fields

  • November 13, 2020
  • 1 reply
  • 509 views

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?

 

 

 

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

}

This topic has been closed for replies.
Correct answer try67

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();

1 reply

try67
try67Correct answer
Braniac
November 13, 2020

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();