Copy link to clipboard
Copied
Hello, I have a problem with print bottom that I need to solve urgently.
I have a complex form that shows / hides a series of fields according to a check box: company or person client.
After completing the form I need the print button to validate required fields but only visible fields: hidden required fields should not be validated before printing.
Someone help me?
Bellow Javascript the code that I used in the print button (this code validates all fields, but I need validate only visible fields)
I read this answer with a code snippet but couldn't embed it in my code correctly: Acrobat Users:
equired fields only required when visible and when hidden not required?
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("Alerta! Voce precisa preencher os campos obrigatórios:\n" + emptyFields.join("\n"));
}
else{
this.print();
}
Copy link to clipboard
Copied
You are not testing for the visible type of fields.