Skip to main content
Participant
May 15, 2017
Answered

Check Required Fields, setFocus (if req) then Print Doc

  • May 15, 2017
  • 1 reply
  • 702 views

I've got follow Javascript code:

for(var i = 0; i < this.numFields; i++)

{

var fieldName = this.getNthFieldName(i);

if ((

this.getField(fieldName).type!="button" && this.getField(fieldName).required==true) &&

(this.getField(fieldName).value=="" || this.getField(fieldName).value=="Off"))

{

app.alert("You must fill in " +fieldName+ " before you can submit the form.");

this.getField(fieldName).setFocus();

break;

}

}

If everthings fine the PDF should print the complete form. How can I insert the this.print string into this script.

This topic has been closed for replies.
Correct answer Bernd Alheit

Use something like this:

var print_it = true;

for(var i = 0; i < this.numFields; i++)

{

var fieldName = this.getNthFieldName(i);

if ((

this.getField(fieldName).type!="button" && this.getField(fieldName).required==true) &&

(this.getField(fieldName).value=="" || this.getField(fieldName).value=="Off"))

{

app.alert("You must fill in " +fieldName+ " before you can submit the form.");

this.getField(fieldName).setFocus();

print_it = false;

break;

}

}

if (print_it) this.print();

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
May 15, 2017

Use something like this:

var print_it = true;

for(var i = 0; i < this.numFields; i++)

{

var fieldName = this.getNthFieldName(i);

if ((

this.getField(fieldName).type!="button" && this.getField(fieldName).required==true) &&

(this.getField(fieldName).value=="" || this.getField(fieldName).value=="Off"))

{

app.alert("You must fill in " +fieldName+ " before you can submit the form.");

this.getField(fieldName).setFocus();

print_it = false;

break;

}

}

if (print_it) this.print();