7 Replies Latest reply on Dec 15, 2011 7:49 AM by kmc27

    ComboBox Out of Sync When Unhiding Fields

    kmc27 Level 1

      Hello All

       

      I put a validation script on a combo box so that when the selection of "Merchant" is made, the script unhides five hidden fields. Instead the script unhides the fields when the option "Special Events" is selected. When I review the script (below) it looks like it should unhide the fields when the "Merchant" option is selected. Any ideas on where I've gone wrong?

       

      An example of the form can be downloaded from here

      http://icestormcity.com/sfl/misc/combo_box_example.pdf

       

       

      if (event.target.value=="Credit") { // user selected "Credit"

          // make the dmm merchant and phone fields hidden

          getField("lbl_dmm").display = display.hidden;

          getField("cbo_dmm_ad_spon").display = display.hidden;

          getField("lbl_buyer").display = display.hidden;

          getField("txt_buyer").display = display.hidden;

          getField("txt_buyer phone").display = display.hidden;

      }

      else if (event.target.value=="ECommerce") { // user selected "ECommerce"

          // make the dmm merchant and phone fields hidden

          getField("lbl_dmm").display = display.hidden;

          getField("cbo_dmm_ad_spon").display = display.hidden;

          getField("lbl_buyer").display = display.hidden;

          getField("txt_buyer").display = display.hidden;

          getField("txt_buyer phone").display = display.hidden;

      }

      else if (event.target.value=="Human Resources") { // user selected "Human Resources"

          // make the dmm merchant and phone fields hidden

          getField("lbl_dmm").display = display.hidden;

          getField("cbo_dmm_ad_spon").display = display.hidden;

          getField("lbl_buyer").display = display.hidden;

          getField("txt_buyer").display = display.hidden;

          getField("txt_buyer phone").display = display.hidden;

      }

      else if (event.target.value=="Marketing") { // user selected "Marketing"

          // make the dmm merchant and phone fields hidden

          getField("lbl_dmm").display = display.hidden;

          getField("cbo_dmm_ad_spon").display = display.hidden;

          getField("lbl_buyer").display = display.hidden;

          getField("txt_buyer").display = display.hidden;

          getField("txt_buyer phone").display = display.hidden;

      }

      else if (event.target.value=="Merchants") { // user selected "Merchants"

          // make the dmm merchant and phone fields visible

          getField("lbl_dmm").display = display.visible;

          getField("cbo_dmm_ad_spon").display = display.visible;

          getField("lbl_buyer").display = display.visible;

          getField("txt_buyer").display = display.visible;

          getField("txt_buyer phone").display = display.visible;

      }

      else if (event.target.value=="Special Events") { // user selected "Special Events"

          // make the dmm merchant and phone fields hidden

          getField("lbl_dmm").display = display.hidden;

          getField("cbo_dmm_ad_spon").display = display.hidden;

          getField("lbl_buyer").display = display.hidden;

          getField("txt_buyer").display = display.hidden;

          getField("txt_buyer phone").display = display.hidden;

      }

       

       

      else if (event.target.value=="Stores") { // user selected "Stores"

          // make the dmm merchant and phone fields hidden

          getField("lbl_dmm").display = display.hidden;

          getField("cbo_dmm_ad_spon").display = display.hidden;

          getField("lbl_buyer").display = display.hidden;

          getField("txt_buyer").display = display.hidden;

          getField("txt_buyer phone").display = display.hidden;

      }

      else if (event.target.value=="Other") { // user selected "Other"

          // make the dmm merchant and phone fields hidden

          getField("lbl_dmm").display = display.hidden;

          getField("cbo_dmm_ad_spon").display = display.hidden;

          getField("lbl_buyer").display = display.hidden;

          getField("txt_buyer").display = display.hidden;

          getField("txt_buyer phone").display = display.hidden;

      }

        • 1. Re: ComboBox Out of Sync When Unhiding Fields
          George_Johnson MVP & Adobe Community Professional

          You should move the code to the Keystroke event, and use event.changeEx instead of event.target.value. The latter does not give you what you think it does in the Validate event.

           

           

          else if (event.changeEx=="Merchants") { // user selected "Merchants"
              // make the dmm merchant and phone fields visible
              getField("lbl_dmm").display = display.visible;
              getField("cbo_dmm_ad_spon").display = display.visible;
              getField("lbl_buyer").display = display.visible;
              getField("txt_buyer").display = display.visible;
              getField("txt_buyer phone").display = display.visible;
          
          • 2. Re: ComboBox Out of Sync When Unhiding Fields
            George_Johnson MVP & Adobe Community Professional

            Also, instead of merely hiding the fields, consider resetting them as well. That way, the fields will always contain valid data.

             

            Finally, your script does not take into account the first item getting selected.

            • 3. Re: ComboBox Out of Sync When Unhiding Fields
              kmc27 Level 1

              Thanks George

               

              I did as you suggested and the issue I was having is resolved, and addressed the first item selection, so thanks very much for your help. I am not sure what you meant by resetting of the fields to ensure valid data. The user will be restricted to whatever values in the dropdown. Sorry for such a basic question, but I'd like to understand the liability that I am missing.

              • 4. Re: ComboBox Out of Sync When Unhiding Fields
                George_Johnson MVP & Adobe Community Professional

                I was thinking about the case of the user selecting "Merchants" item, fills in the three fields, and then decides to select a different item (e.g., Credit) that causes the fields to be hidden. The hidden fields will still contain the values that the user entered, but they do not apply to the Functional Area item that is selected. This may not matter if the form will only be used for printing, but if you will be extracting the form data, the values in the three hidden fields may not apply to the selected item in the initial combo box.

                 

                I realize the form you posted was just a test, but also consider making the label fields read-only so they won't be in the tab order and the user won't be able to change their values.

                 

                Also, another way to display default text that the user doesn't then have to erase is to use a custom Format script like:

                 

                // Show hint if field is empty

                if (!event.value) event.value = "Buyer's name";

                 

                This just makes it easier for the user when entering data and ensures that it will reappear when the field is empty.

                • 5. Re: ComboBox Out of Sync When Unhiding Fields
                  kmc27 Level 1

                  Thanks, I understand what you mean now. It could be confusing to keep unused selections if the user goes back to any choice other than "Merchants"

                   

                  To make that happen, I went to the fields that I would want to be reset if they are hidden, and added this custom validation script.

                   

                  if (display = display.hidden) event.target.value = event.target.defaultValue ;

                   

                  This seems like this should reset the field if the field is hidden (controlled by the script on the Functional Area combobox). Instead, the (non default value) choice is retained, and it the field's visibility is no longer controlled by the Functional Area field.  Am I at least on the right track here in implementing your suggestion?

                  • 6. Re: ComboBox Out of Sync When Unhiding Fields
                    George_Johnson MVP & Adobe Community Professional

                    Get rid of that code and place the following at the beginning of the script:

                     

                     

                    // Reset the data entry fields that get hidden/shown
                    
                    resetForm(["cbo_dmm_ad_spon", "txt_buyer", "txt_buyer phone"]);
                    

                     

                    This resets those fields regardless of whether they're hidden or shown when a selection is made in the combo box, which is what you want.

                    • 7. Re: ComboBox Out of Sync When Unhiding Fields
                      kmc27 Level 1

                      OK, it's working now. Thanks for your help and suggestions. I improved the useability of some of the other fields on myform based on the advice you gave me in this thread.

                       

                      Thanks again