Highlighted

Include Drop Boxes in Required fields check and add print functionality

New Here ,
Jun 25, 2020

Copy link to clipboard

Copied

Hello all,

New to this (javascript) so please be gentle.

I have forms for work that need to be accessed and printed remotely.

I have Javascript code from try67 that does the required field check and throws a message if fields are left blank.

Code as follows:

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

}

 

Is there a way to add a check of drop down boxes to this?

 

Also if all the required fields and drop boxes have been filled in is there a bit of code to add that will then open the print dialogue box?

I tried adding another action to print but once you click ok on the error message it automatically opens the print dialogue without forcing the user to rectify the error.

I have spent 3 days trying to research this and and have come up blank.

 

Thanks in advance to any and all help.

Topics

PDF forms

Views

44

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

Include Drop Boxes in Required fields check and add print functionality

New Here ,
Jun 25, 2020

Copy link to clipboard

Copied

Hello all,

New to this (javascript) so please be gentle.

I have forms for work that need to be accessed and printed remotely.

I have Javascript code from try67 that does the required field check and throws a message if fields are left blank.

Code as follows:

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

}

 

Is there a way to add a check of drop down boxes to this?

 

Also if all the required fields and drop boxes have been filled in is there a bit of code to add that will then open the print dialogue box?

I tried adding another action to print but once you click ok on the error message it automatically opens the print dialogue without forcing the user to rectify the error.

I have spent 3 days trying to research this and and have come up blank.

 

Thanks in advance to any and all help.

Topics

PDF forms

Views

45

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
Most Valuable Participant ,
Jun 26, 2020

Copy link to clipboard

Copied

I wrote this code... It already does check check-box fields, but you can make it more universal by changing this line:

if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off"))

To:

if (f.valueAsString!=f.defaultValue)

 

And to open the Print dialog if all the requires fields are filled-in add this line to the end of it:

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...
Adobe Employee ,
Jun 26, 2020

Copy link to clipboard

Copied

Hi There,

 

Thanks for your concern.

Is there an issue with Printing at your end? Can you descript the issue, so that we can help you with the same.

 

Regards,
Swapnil Srivastava

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...
Resources
One Stop Solution for Acrobat
Edit a PDF