Skip to main content
vickib85760701
Participating Frequently
May 7, 2020
Question

Javascript to suggest requried fields before fillable pdf document will SAVE

  • May 7, 2020
  • 1 reply
  • 960 views

I've seen scripts written to show an error when a prospect doesn't fill in all of the required fields. I'd like a SAVE button that will show the empty fields before saving the document. I know I can't override the viewer using the save or save as from the menu. 

 

The one below is working great for me. I'd just like to have code at the end that will SAVE the file if the form is complete. I don't want to use submit. I don't' want the pdf going into an email draft folder.

 

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

This topic has been closed for replies.

1 reply

vickib85760701
Participating Frequently
May 7, 2020

Want to mention GILIAD is where I got the script I mentioned.

try67
Community Expert
Community Expert
May 7, 2020

Yes, that's me (although it's actually Gilad)...

This code doesn't submit the file. It just checks that the required fields are filled-in.

What you can do is add the following to the end of it in order to open the Save As dialog if all is well:

 

else app.execMenuItem("SaveAs");

vickib85760701
Participating Frequently
May 7, 2020

I cannot thank you enough Gilad!

I've been searching the web for this answer for days. Well, first I found your script to check the required fields and it worked like a charm. Now, I'm going to add that last piece and will be a rock star at work. I wish I could do what you do! It's magic.