13 Replies Latest reply on Feb 10, 2016 1:05 PM by Angus24

    Force User to Complete a Field

    Angus24 Level 1

      I’m working in Acrobat Pro DC.

       

      I have a dropdown (DepartAnswer) that contains the choices Yes or No. If the user chooses No, they go on to the next field. If they choose Yes 2 text fields appear; one that is Read Only, with default text of: - keep till:  The second field (AvailDate) is empty for the user to put a date.

       

      What has been requested of me is to have the AvailDate field be a mandatory field, if the user has chosen Yes, then there must be a date in the AvailDate field. This form is e-mailed via a button and they do not want the form e-mailed without that field (AvailDate) completed – not tabbed over and left empty.

       

      Is it possible to force the user to complete this field before moving on?

        • 1. Re: Force User to Complete a Field
          George_Johnson MVP & Adobe Community Professional

          You can mark the field as Required and the submit form action won't be allowed to take place unless it it filled-in.

           

          Another approach is to use JavaScript, where you have the opportunity to check fields more completely and give more helpful feedback to the user. The script would first check the required fields and only proceed with the submitForm statement if everything checks out.

          • 2. Re: Force User to Complete a Field
            Angus24 Level 1

            Ok, this may sound silly, but I have done that.  On the AvailDate field I have checked Required under the General tab, the outline of the field turns red. But I am still able to click on the button to e-mail the form and it does so with AvailDate empty.

             

            Am I doing something wrong?

            • 3. Re: Force User to Complete a Field
              Karl Heinz Kremer Adobe Community Professional

              How are you emailing the document? There are different methods, and the "required" fields will only be checked when you are doing a true forms submission. If you are using the Doc.mailDoc() method for example to email your document, that is not a forms submission, and it will therefore not check the required fields.

              • 4. Re: Force User to Complete a Field
                Angus24 Level 1

                Under the button properties on the Actions tab for Select Trigger I have Mouse Up, for the Select Action I have Run a JavaScript.

                This is the coding I have associated with the button:

                 

                //cToAddr is the e-mail address you are sending to
                var cToAddr = ""

                //cSubLine is the Subject line with the name of the employee the 24-2812 pertains to
                var cSubLine = "24-2812 - " + this.getField("DD1").value + " for " + this.getField("Text2").value + ", " + this.getField("Dropdown6.0").value;

                //this produces the e-mail
                this.mailDoc({bUI:true, cTo: cToAddr, cSubject: cSubLine});

                 

                The users wanted the subject line to be completed based on some of the fields in the form.

                • 5. Re: Force User to Complete a Field
                  try67 MVP & Adobe Community Professional

                  The mailDoc method doesn't enforce the required fields validation before executing. You'll have to do it yourself using a script, or switch to using the submitForm method, which does makes sure that all of the required fields are filled-in before sending the file to the target URL.

                  • 6. Re: Force User to Complete a Field
                    Angus24 Level 1

                    So the way that I have the button set up is the mailDoc method?

                     

                    If I use the submitForm I don't have the ability to place field values in the subject line as I do with JavaScript...correct?

                     

                    What would be the script to get the user to enter information into AvailDate?

                    • 7. Re: Force User to Complete a Field
                      try67 MVP & Adobe Community Professional

                      - Yes, you're using mailDoc.

                      - No, that's not correct. You can use this code to do it:

                       

                      //cToAddr is the e-mail address you are sending to
                      var cToAddr = ""
                      
                      //cSubLine is the Subject line with the name of the employee the 24-2812 pertains to
                      var cSubLine = "24-2812 - " + this.getField("DD1").value + " for " + this.getField("Text2").value + ", " + this.getField("Dropdown6.0").value;
                      
                      //this produces the e-mail
                      this.submitForm({cURL: "mailto:" + cToAddr + "?subject=" + cSubLine, cSubmitAs: "PDF"});
                      

                       

                      - Using the code above they will not be able to submit the file unless they filled in all required fields first.

                      1 person found this helpful
                      • 8. Re: Force User to Complete a Field
                        Angus24 Level 1

                        Thank you for the information and the coding, it worked perfectly. Exactly what I was looking for thank you!

                         

                        You all are awesome.

                        • 9. Re: Force User to Complete a Field
                          Angus24 Level 1

                          I ran into an issue; because the AvailDate filed is checked required and AvailDate only appears if the dropdown (DepartAnswer) is Yes, if I choose No for the dropdown (DepartAnswer) I cannot e-mail the form because AvailDate is a required field.

                           

                          Is there a way to have a field required without checking the required box?

                           

                          In other words, is there some type of coding that I can use so if AvailDate is visible then entering information into the field is required, however if it is hidden it can be blank and the form can still be e-mailed?

                          • 10. Re: Force User to Complete a Field
                            George_Johnson MVP & Adobe Community Professional

                            You can use JavaScript to make the field required or not, just like you make those two text fields visible or not, depending on the state of the dropdown. The property name is "required".

                            • 11. Re: Force User to Complete a Field
                              Angus24 Level 1

                              How would I do that? This is the coding I have for AvailDate:

                               

                              var v = this.getField("DD1").value;

                              var y = this.getField("DepartAnswer").value;

                               

                              if(v=="Departing"&&y=="Yes")event.target.display=display.visible;

                              if(v=="Departing"&&y=="No")event.target.display=display.hidden;

                              • 12. Re: Force User to Complete a Field
                                George_Johnson MVP & Adobe Community Professional

                                f (v == "Departing" && y == "Yes") {

                                     event.target.display = display.visible;

                                     event.target.required = true;

                                } else if (v == "Departing" && y == "No") {

                                    event.target.display = display.hidden;

                                    event.target.required = false;

                                }

                                • 13. Re: Force User to Complete a Field
                                  Angus24 Level 1

                                  Oh, thank you so much George!  Just what I needed to complete this form.