9 Replies Latest reply on Oct 27, 2016 11:01 AM by Karl Heinz Kremer

    Validating required fields in Acrobat X

    jlmorton2010 Level 1

      I created a form in Acrobat X with dropdowns, radio buttons and text fields that are "required" to be completed before the form is sent to another department. I would like a javascript written to tie to Print and Save As buttons I have created that would check these fields before the action is completed. I have checked this forum and other forums and found pieces but I can't get them to work together.

       

      Dropdowns - 'Request in Person' or 'Request by Other' (a selection must be made in one of these fields)

      Dropdown - Wire Fees (a selection must be made in this fields)

      Radio Buttons - Method of Payment, Funds Available, Account Analysis (a selection must be made in all of these fields)

      Text Fields - Beneficiary Name, Beneficiary Account Number, Beneficiary Street Address, Beneficiary City, State, Zip Code

       

       

      If possible, could the javascript also include a warning message that those fields need to be completed?

       

      Any and all help would be greatly appreciated on this!!

        • 1. Re: Validating required fields in Acrobat X
          jlmorton2010 Level 1

          The fields referenced above are marked as required under properties.

          • 2. Re: Validating required fields in Acrobat X
            Karl Heinz Kremer Adobe Community Professional

            The "required" property that you can assign to fields only works for one specific case: It works for text fields (and not dropdown, checkboxes or radio buttons), and only when you use a "forms submissions". This means that saving or printing will never look at the required property.

             

            What you need to do is to implement your own validation routine that looks at all fields that have the "required" property set (or, you can make this independent from the required property and your validation routine just looks at all fields). When a required field is missing the correct information, you would display a dialog box that instructs the user to provide the missing information. You cannot however interrupt the print or save function - the file will still be printed or saved. What you can do is mark the file as "incomplete" by e.g. having a large form field on top of all other fields that tells the user that the form is not complete. This way, there is no question about a printout - you know if the form was completed, or not.

             

            To hook your own validation function into the print (and/or save) function, you would use a document action script.

            • 3. Re: Validating required fields in Acrobat X
              jlmorton2010 Level 1

              Would you be able to help me with writing the script for the document? I have learned on the fly the easy javascript but this is throwing me for a loop.

               

              Also, would you know a good book for me to use to learn Java? I have looked but haven't found anything.

               

              Thanks in advance for any and all help on this.

              • 4. Re: Validating required fields in Acrobat X
                Karl Heinz Kremer Adobe Community Professional

                There area many books out there to learn JavaScript (it's not "Java" - that's a completely different programming language), but almost all of them are written for browser based JavaScript. When you look at any JavaScript implementation, there are two parts: The core JavaScript language, which is the same across the board, and then application specific extensions, which are all - as the name implies - very specific to each application. This means you cannot use these browser specific extensions in Acrobat and vice versa. This means that it's hard to figure out (as somebody without any experience in JavaScript) where this dividing line is. I am only aware of one book that is specifically for Acrobat: Beginning JavaScript for Adobe Acrobat

                 

                Do you know how to create document acting like "Document Will Save" or "Document Will Print"?


                Do you know how to loop over all fields in a document?

                • 5. Re: Validating required fields in Acrobat X
                  jlmorton2010 Level 1

                  I don't know how to loop over all fields...if you are referring to the "Document Will Save / Print" items under Tools, JavaScript...I understand how to use them.

                   

                  I downloaded the sample from the book you suggested....amazing...if the rest of the book is as good as the first two chapters, this will be the first step in learning...Thank you!

                  • 6. Re: Validating required fields in Acrobat X
                    Karl Heinz Kremer Adobe Community Professional

                    Let's say you want to loop over all fields in a form, and then process text fields, radio buttons and dropdown. You can use something like this in your document action:

                     

                    for (var i=0; i<this.numFields; i++) {
                        var f = this.getField(this.getNthFieldName(i));
                        if (f != null) {
                            if (f.type == "text") {
                                // do something
                            }
                            else if (f.type == "radiobutton") {
                                // do something
                            }
                            else if (f.type == "combobox") {
                                // do something
                            }
                        }
                    }
                    

                     

                    You would have to implement the code that actually checks the fields, and then, you would have to add code that would report the problem. In the most simplistic case, you can just use an app.alert("Data is missing"); alert box, but you may want to inform the user about what exactly is missing.

                    • 7. Re: Validating required fields in Acrobat X
                      jlmorton2010 Level 1

                      Could I add code to highlight the missing data fields and then have the app.alert state "Highlighted fields are required and need to have information entered before processing"

                      • 8. Re: Validating required fields in Acrobat X
                        gkaiseril MVP & Adobe Community Professional

                        Yes you can but you need to add more code. to change either the border properties of the fillColor property.

                         

                        This approach of scanning all of the fields and either testing specific field names or the "required" property has been the same since Acrobat 4.0. The only field types that can cause an issue are button fields since they do not have the "required "property".

                        • 9. Re: Validating required fields in Acrobat X
                          Karl Heinz Kremer Adobe Community Professional

                          Take a look here for a tutorial about using color with PDF form fields: https://acrobatusers.com/tutorials/using-colors-acrobat-javascript