3 Replies Latest reply on May 30, 2015 9:25 PM by Karl Heinz Kremer

    Invalid Text for a Document print event

    WilliB

      I have been trying to find an answer to this for a couple days now any help would be much appreciated.

       

      Here is what I am trying to accomplish.

           I have a document that I would like to be completely filled out before our data entry inputs that data from the fields.

           I know with a print event there is no way to prevent the user from printing, so what I would like is to have the document print INVALID in big text across the form so date entry does not waste too much time

           Also I would like for a message to pop up that alerts the user they did not fill out the form in its entireity.

       

      I am pretty new to Java script but I think if anyone could point me in he write direction I could figure it out.

       

      Thanks again

        • 1. Re: Invalid Text for a Document print event
          Karl Heinz Kremer Adobe Community Professional

          Take a look at the Document Will Print and Document Did Print event handlers (Tools>JavaScript>Set Document Actions). To do a validation before you print, you just iterate over all fields that you require input for and check if they all contain valid data. What is considered valid data depends on your specific form. This could mean that a text field contain some data, but it could also mean that a text field contains data in a certain format.

           

          You can set the "required" flag for a field, and then just check that in your loop:

           

          var formValid = true;
          for (var i=0; i<this.numFields; i++) {
            var f = this.getField(this.getNthFieldName(i));
            if (f.required) {
                // do something and set formValid to false when the field does not contain valid data and call break
            }
          }
          

           

          To show a message, you have different options. I've used two of them:

           

          1) You can create a form field that covers the complete page and contains the string "INVALID" in large letters. In the "WillPrint" event, you would then show this field using e.g.

          this.getField("INVALID").display = display.visible;
          

           

          and then in the "Did Print" event, you hide it again:

           

          this.getFIeld("INVALID").display = display.hidden;
          

           

          If you want more control over formatting of the string, you can create a layer that is hidden by default and you would only show it during a print operation, and then hide it again after you are done printing.

          • 2. Re: Invalid Text for a Document print event
            WilliB Level 1

            Can I combine the two scripts?

            So when it comes back true, all fields marked " required" come back complete the document prints as intended.

             

            However, if one or more of the required fields are not filled out, in this case they just have to have something in them.

            The event would return false and make the field I have hidden visible and also pop up a window alerting them of so.

             

            Thanks again for your help.

            • 3. Re: Invalid Text for a Document print event
              Karl Heinz Kremer Adobe Community Professional

              Yes, you can certainly combine the two tasks into one script.