6 Replies Latest reply on Jan 12, 2013 3:22 PM by ppmax

    Listbox defaultValue = null?

    ppmax

      I created a listbox object, created 4 listbox items, and then cleared the listbox default value by clicking in the whitespace where the listbox items are displayed.

       

      I call listbox.defaultValue and nothing is returned. I call listbox.value and nothing is returned.

       

      After selecting an item, I want to clear the selection on the OnBlur event which calls a custom reset() fundtion.

       

      In the reset function I call listbox.defaultValue = null and get a set error.

       

       

      I've tried repopulating the listbox OnBlur, but doing so always sets the first listbox item as the defaultValue.

       

      How can I do this?

       

      thx

      PP

        • 1. Re: Listbox defaultValue = null?
          George_Johnson MVP & Adobe Community Professional

          That's interesting and not something I've ever noticed before, probably because I rarely use list boxes.  I get zero length strings when no item is selected for both the value and default value, and the field isn't included when the form data is exported. When the field is reset, it does revert back to no items being selected. To reset, use the resetForm mothed, not what you showed above.

          • 2. Re: Listbox defaultValue = null?
            ppmax Level 1

            Thanks George--I appreciate the reply.

             

            I had forgotten about resetForm and passing in an array--thanks for the suggestion.

             

            Ijust tried and unfortunately the resetForm method does make a default selection in the listbox. Are you seeing otherwise?

             

            thx

            PP

            • 3. Re: Listbox defaultValue = null?
              try67 MVP & Adobe Community Professional

              When a list-box is reset it doesn't return to the state where no items are

              selected, but to the selection of the default value.

              The default value is the item that is very lightly highlighted when you

              switch to the Options tab in the Properties window of the field.

              I find this method of selecting a default value very inconvenient because

              it's very easy to change the selection by accident.

              AFAIK, if the field has items in it it's not possible to return to the

              state where nothing is selected at all.

              • 4. Re: Listbox defaultValue = null?
                ppmax Level 1

                >>When a list-box is reset it doesn't return to the state where no items are selected, but to the selection of the default value.

                 

                This is what I see too, except for one case where no default item is selected in the field options gui. I was hoping this technique would get me where I want to go--as you can see no item is selected as the default:

                Screen Shot 2013-01-12 at 8.54.19 AM.JPG

                 

                After exiting form edit and saving the file, this.getField("listBox").defaultValue is empty. This is great...but it's strange that you can create a condition in the GUI that is not possible with the javascript API. In other words, after selecting an item in the listbox, setting this.getField("listBox").defaultValue = "" creates a set error. So you cant return to a state that previously existed.

                 

                >>AFAIK, if the field has items in it it's not possible to return to the state where nothing is selected at all.

                 

                I'm slowly reaching (reached?) this conclusion as well. Thanks for your comments and help.

                 

                PP

                • 5. Re: Listbox defaultValue = null?
                  George_Johnson MVP & Adobe Community Professional

                  Yes, I am seeing otherwise. When the default value is nothing, it gets set to nothing when the form is reset. As you noted, it does not allow you to set the field value to an empty string via JavaScript. This is with Acrobat 9 and I haven't tested anything else yet. Note that if you allow multiple selections, the user is able to deselect all items so that none are selected.

                  • 6. Re: Listbox defaultValue = null?
                    ppmax Level 1

                    Good gosh, you're right! I was still using my manual reset which repopulated the list box rather than calling resetForm(['listBox']);

                     

                    Thanks much George--you checking it out made me take a 2nd look and now we have a winner.

                     

                    Have a good weekend

                    PP