2 Replies Latest reply on Dec 15, 2016 5:44 AM by KevinCifala

    Want to prevent email/print through form button if required fields are blank (but allow blanks in non-required fields)


      Hi All,


      I understand that technically I cannot completely restrict printing and that's fine. I have a print button on my form (with about 25 fields; some required others not) that I'm looking to use some javascript on that will check to see if all the required fields are filled in before allowing to print (any any type of button action). It's OK to print if all the required fields are filled in but some of the non required fields are blank. I found a good deal of answers from other posts but I think my issue (possibly) is that I have several drop down boxes in my form?


      I've pasted what I've found so far after doing some forum searching. My problem is that even when I fill in every single field and drop down in my form, I still get the alert saying I need to fill in required fields (instead of printing). My ultimate goal here is when the button is clicked, it checks to see if only the required fields are filled and if they aren't it returns a message saying fields need to be complete and highlights them in red. If the user then enters the required info (but can leave the non-required fields blank) then the fields turn back to their original color (gray) and the person is allowed to use the button action (in this case print).




      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.valueAsString=="") || (f.type=="checkbox" && f.value=="Off"))


      f.strokeColor = color.red;   //Highlights the required fields with red outline

      else f.strokeColor = color.gray; //Highlights the filled in fields with gray outline




      if (emptyFields.length>0) {

           app.alert("WAIT! You must fill in all of the required fields before printing this form:\n");


      else this.print();