4 Replies Latest reply on Jan 4, 2015 11:00 AM by bw200

    Alert user when saving PDF if required fields are empty/null

    bw200

      Greetings,

       

      I've read a fair number of threads on this topic. I am not trying to force the user to stay in a field or otherwise be annoyed. I would just like to alert the user when they save the PDF if there are required fields that have not been filled out. The alert message would simply be a polite reminder to complete the form before sending.

       

      I'm using Acrobat XI Pro.

       

      1) Is the Other Tasks/Set Document Actions/Document Will Save the correct place to use a script in this case?

       

      2) Would the script need to check each required field by name? Or is there a way to reference all required fields in the document?

       

      3) I've seen some examples like this:

       

      f = getField(event.target.name)

      if (f.value.length == 0)

          {

          f.setFocus()

          app.alert("This field is required. Please enter a value.")

          }

       

      However it has some issues with respect to closing the alert dialog and so forth. Can anyone provide a sample script to get me started?

       

      Thanks!

        • 1. Re: Alert user when saving PDF if required fields are empty/null
          George_Johnson MVP & Adobe Community Professional

          Exactly how you check a field for being empty depends on what type of field it is. For text fields, you should get the field's value as a string and compare it to an empty string, something like:

           

          var val = getField("Text1").valueAsString;

          if (val) {

              app.alert("Field is not empty");

          }

           

          If there is a default value that needs to be changed, you would compare to the default value:

           

          var f = getField("Text1");

          var val = f.valueAsString;

          if (val !== f.defaultValue) {

              app.alert("Field value is OK");

          }

           

           

          For check boxes and radio buttons, you'd compare to the string "Off", which means none in the group is selected.

           

          For dropdowns (combo boxes) and list boxes, there is normally one value selected, so you would have to get the value and check against the default value (or something else) to see if the field is properly filled in.

           

          You could place the script there, but I usually use a separate button that I encourage the user to click in order to check the field. The problem with using the Will Save event is you can't prevent the save from happening.

           

          The script can loop through all of the fields (and test all required ones), or you could set up an array of field names to check.

          • 2. Re: Alert user when saving PDF if required fields are empty/null
            bw200 Level 1

            George,

             

            Many thanks - this is a great help!

             

            Just one quick check: is the Set Document Actions/Document Will Save the correct place to use the script?

             

            • 3. Re: Alert user when saving PDF if required fields are empty/null
              gkaiseril MVP & Adobe Community Professional

              I would look at the "Will Close" action so the process is run as part of closing the document. You would also need to check the "dirty" property to see if the form had been changed since the last save.

              • 4. Re: Alert user when saving PDF if required fields are empty/null
                bw200 Level 1

                Thanks GKaiseril - much appreciated.