4 Replies Latest reply on Feb 2, 2012 3:35 PM by kmc27

    Can Validation Script Discern If a Field is Hidden?

    kmc27 Level 1

      Hello All

       

      I use the validation script below to check for data in required fields on my form. I recently modified the form, changing three of the required fields from visible to hidden fields. The three fields are hidden unless the user makes a specific selection from a combo box. Then the three fields become visible, and if visible, should be required.

       

      I am stuck on how to tell the script to work as follows:

       

      1. If the three fields controlled by the combo box are visible, then they should be checked for the required data

      2. If the three fields controlled by the combo box are hidden, then the script should ignore checking them for the required data

       

      The three hidden/unhidden fields in the script are f5, f6, f7. Is there a way in the validation portion of the script to have it determine if the field is hidden or visible, and if visible check it for the required data?

       

      Thanks in advance for any ideas on this.

       

       

      var m = this.getField("txt_subject");

      var mysubject = m.value + " - Request Form Submission";

      var cType = "Reader";

      var cVersion = "< 7";

      var nWarning = 1;

      var cMsg1 = "This form cannot be submitted with your version of Acrobat Reader.";

      var cMsg2 = "You must use Acrobat Reader version 7 or higher.";

      // If Reader 6 or below is being used, display message telling user that "Email" and "Save Data" buttons don't work.

      if (app.viewerType == cType && app.viewerVersion == cVersion)

      app.alert(cMsg1 + cMsg2, nWarning)

      else {

                f1 = this.getField("txt_date");

                f2 = this.getField("txt_requested by")

                f3 = this.getField("txt_requested by phone");;

                f4 = this.getField("cbo_functional area");

        f5 = this.getField("cbo_dmm_ad_spon");

                f6 = this.getField("txt_buyer");

                f7 = this.getField("txt_buyer phone");

                f8 = this.getField("cbo_dmm_finan_spon");

        f9 = this.getField("tbx_coop_dmm");

                f10 = this.getField("tbx_load_dmm");

                f11 = this.getField("tbx_expected roi");

                f12 = this.getField("txt_event");

                f13 = this.getField("txt_start date");

                f14 = this.getField("cbo_am or pm");

                f15 = this.getField("txt_target audience");

                                  if (f1.value == "")

                          {app.alert ('Please enter the date you are making this request".');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f1.setFocus();}

                          else if (f2.value == "Person making request")

                                    {app.alert ('The "Requested by" line cannot be blank. Please type the name of the person requesting this ad.');

                  if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f2.setFocus();}

                          else if (f3.value == "Phone #")

                                    {app.alert ('Please type the phone number of the person requesting this project.');

                  if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f3.setFocus();}

                                else if (f4.value == "Select a Functional Area")

                                    {app.alert ('Please select a Functional Area.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f4.setFocus();}

                                 else if (f5.value == "Select a DMM")

                                    {app.alert ('Please select a DMM.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f5.setFocus();}

                                          else if (f6.value == "Buyer's name")

                                    {app.alert ('Please enter the name of the Buyer.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f6.setFocus();}

                          else if (f7.value == "Phone #")

                                    {app.alert ('Please type the Buyer\'s phone number.');

                  if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f7.setFocus();}

                else if (f8.value == "Select a Financial Sponsor")

                                    {app.alert ('Please enter the financial sponsor.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f8.setFocus();}

                      else if (f9.value == "Enter dollars or a % amount.")

                                    {app.alert ('Please enter a dollar or percent amount for coop.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f9.setFocus();}

                     else if (f10.value == "Enter a dollar amount.")

                                    {app.alert ('Please enter an amount for load.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f10.setFocus();}

                     else if (f11.value == "Enter a dollar amount.")

                                    {app.alert ('Please enter the expected ROI amount in dollars.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f11.setFocus();}

                     else if (f12.value == "")

                                    {app.alert ('Please enter the Event name.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f12.setFocus();}

                      else if (f13.value == "")

                                    {app.alert ('Please enter a start date for this email.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f13.setFocus();}

                   else if (f14.value == "Select AM or PM")

                                    {app.alert ('Please select AM or PM for the Deployment time.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f14.setFocus();}

                      else if (f15.value == "")

                                    {app.alert ('Please describe the target audience for this email.');

                if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

                f15.setFocus();}

                   else

                                    // Email PDF.

                                    this.mailDoc(true, "requestforms@ysdvzl.com", "", "", mysubject);}

        • 1. Re: Can Validation Script Discern If a Field is Hidden?
          AcroBishop

          if(f5.display == display.visible && f5.value == "Select a DMM") {

            app.alert ('Please select a DMM.');

            if(typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0) f5.setFocus();

          }

           

          I would also suggest setting a varialbe equal to that comparison that you do over and over again, i.e.

           

          var correctVersion = (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)

           

          Then your code will look like this for each block...

           

          if(f5.display == display.visible && f5.value == "Select a DMM") {

            app.alert ('Please select a DMM.');

            if(correctVersion) f5.setFocus();

          }

          • 2. Re: Can Validation Script Discern If a Field is Hidden?
            kmc27 Level 1

            AcroBishop

             

            Thank you for your help with my question and for the suggestion to clean up the script. I ended up having to make a few other changes to the form itself, but when I did implement the script modifications you suggested, the form worked perfectly.

             

            Thanks again.

            • 3. Re: Can Validation Script Discern If a Field is Hidden?
              kmc27 Level 1

              I went through the form, and realized I am partially where I need to be: The required fields script checks the first of the three unhidden fileds, but then skips the other two.

               

              To recap, I have a combobox that, if the user makes a specific selection, that selection will make three hidden fields visible. When checking the fields on the form, the required fields script should then proceed as follows:

               

              1. If the three fields controlled by the combo box are visible, then they should be checked for the required data

              2. If the three fields controlled by the combo box are hidden, then the script should ignore checking them for the required data

               

              The three hidden  fields are:

               

              cbo_dmm_ad_spon

              txt_buyer

              txt_buyer phone

               

              When the three fields are visible the script checks the first one, cbo_dmm_ad_spon, but skips checking txt_buyer and txt_buyer phone, and instead goes on to the cbo_dmm_finan_spon field.

               

              I believe I've correclty implemented what AcroBishop recommended. Does anyone see where I may have gone wrong?

               

               

               

               

              var correctVersion = (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0);

              var m = this.getField("txt_subject");

              var mysubject = m.value + " - Email Request Form Submission";

              var cType = "Reader";

              var cVersion = "< 7";

              var nWarning = 1;

              var cMsg1 = "This form cannot be submitted with your version of Acrobat Reader.";

              var cMsg2 = "You must use Acrobat Reader version 7 or higher.";

              // If Reader 6 or below is being used, display message telling user that "Email" and "Save Data" buttons don't work.

              if (app.viewerType == cType && app.viewerVersion == cVersion)

              app.alert(cMsg1 + cMsg2, nWarning)

              else {

                        f1 = this.getField("txt_date");

                        f2 = this.getField("txt_requested by")

                        f3 = this.getField("txt_requested by phone");;

                        f4 = this.getField("cbo_functional area");

                f5 = this.getField("cbo_dmm_ad_spon");

                        f6 = this.getField("txt_buyer");

                        f7 = this.getField("txt_buyer phone");

                        f8 = this.getField("cbo_dmm_finan_spon");

                f9 = this.getField("tbx_coop_dmm");

                        f10 = this.getField("tbx_load_dmm");

                        f11 = this.getField("tbx_expected roi");

                        f12 = this.getField("txt_subject");

                        f13 = this.getField("txt_objective");

                        f14 = this.getField("txt_start date");

                        f15 = this.getField("cbo_am or pm");

                        f16 = this.getField("txt_target audience");

                                          if (f1.value == "")

                                  {app.alert ('Please enter the date you are making this request".');

                         if(correctVersion) f1.setFocus();}

                                  else if (f2.value == "Person making request")

                                            {app.alert ('The "Requested by" line cannot be blank. Please type the name of the person requesting this ad.');

                         if(correctVersion) f2.setFocus();}

                                  else if (f3.value == "Phone #")

                                            {app.alert ('Please type the phone number of the person requesting this project.');

                         if(correctVersion) f3.setFocus();}

                                        else if (f4.value == "Select a Functional Area")

                                            {app.alert ('Please select a Functional Area.');

                         if(correctVersion) f4.setFocus();}

                              else if(f5.display == display.visible && f5.value == "Select a DMM") {

                app.alert ('Please select a DMM.');

                         if(correctVersion) f5.setFocus();}

                                   else if (f6.display == display.visible && f6.value == "Buyer's name")

                                            {app.alert ('Please enter the name of the Buyer.');

                         if(correctVersion) f6.setFocus();}

                                  else if (f7.display == display.visible && f7.value == "Phone #")

                                            {app.alert ('Please type the Buyer\'s phone number.');

                         if(correctVersion) f7.setFocus();}

                        else if (f8.value == "Select a Financial Sponsor")

                                            {app.alert ('Please enter the financial sponsor.');

                         if(correctVersion) f8.setFocus();}

                              else if (f9.value == "Enter dollars or a % amount.")

                                            {app.alert ('Please enter a dollar or percent amount for coop.');

                         if(correctVersion) f9.setFocus();}

                             else if (f10.value == "Enter a dollar amount.")

                                            {app.alert ('Please enter a dollar amount for load.');

                         if(correctVersion) f10.setFocus();}

                             else if (f11.value == "Enter a dollar amount.")

                                            {app.alert ('Please enter the expected ROI amount in dollars.');

                         if(correctVersion) f11.setFocus();}

                             else if (f12.value == "Launch? Expanded assortment? New sizes?")

                                            {app.alert ('Please enter the subject of this email.');

                         if(correctVersion) f12.setFocus();}

                                               else if (f13.value == "Drive sales? Informational?")

                                            {app.alert ('Please enter the objective of this email.');

                         if(correctVersion) f13.setFocus();}

                              else if (f14.value == "")

                                            {app.alert ('Please enter a start date for this email.');

                         if(correctVersion) f14.setFocus();}

                           else if (f15.value == "Select AM or PM")

                                            {app.alert ('Please select AM or PM for the Deployment time.');

                         if(correctVersion) f15.setFocus();}

                              else if (f16.value == "")

                                            {app.alert ('Please describe the target audience for this email.');

                         if(correctVersion) f16.setFocus();}

                           else

                                            // Email PDF.

                                            this.mailDoc(true, "requestforms@ysdvzl.com", "", "", mysubject);}

              • 4. Re: Can Validation Script Discern If a Field is Hidden?
                kmc27 Level 1

                I realize an example will be easier to visualize - i put an example of the problem I am experiencing here http://www.icestormcity.com/sfl/misc/form_example.pdf

                 

                Any ideas on what might be throwing the script off would be appreciated.