7 Replies Latest reply on Feb 1, 2011 2:25 AM by JabbyPandaUA

    Using Validator with mx:ComboBox causes it to auto-close

    jer.bradley

      I've recently ported a 3.x flex app to Flex 4. I've run in to a bug that causes all mx:ComboBoxes to close the first time the user attempts to open the drop down list. Subsequent attempts to open the box work fine.

       

      Example:

       

      <mx:ComboBox id="typeId" dataProvider="{fMechanismTypes}"
                                   labelField="name" prompt="Select..."
                                   change="handleTypeChange( )"
                                   creationComplete="initTypeValidator();"
                                   focusOut="tabValidationCheck()"/>
      
      private function initTypeValidator():void {
                  fTypeValidator.source = typeId;
                  fTypeValidator.property = "selectedIndex";
                  fTypeValidator.minValue = 0;
                  fTypeValidator.lowerThanMinError = "This field is required.";
              }
      

       

      If I don't initialize fTypeValidator, the combobox works correctly.

       

      Anyone experience this?

        • 2. Re: Using Validator with mx:ComboBox causes it to auto-close
          adamzucchi

          I have also ran into this problem.  Did you ever find a way to resolve this issue?

           

          Thanks.

           

          Adam

          • 3. Re: Using Validator with mx:ComboBox causes it to auto-close
            adamzucchi Level 1

            It appears a Flex ComboBox and a String Validator with the properties of being required as true, and the property of text, forces the ComboBox to close when selecting an item via the keyboard.  This auto close only happens when making the initial selection from the initial empty string or 0 index.  After a valid selection has been made, the user is able to use the keyboard to select any other values, and the ComboBox display remains open.  I have attempted to write my own ComboBox class that extends the Flex ComboBox, which would do custom open and close functionality, however I have been unsuccessful.  My goal is to have this ComboBox remain open during Keyboard input.  If the StringValidator required property is set to false, the box does not auto close.

             

            Any help on this topic would be greatly appreciated.

             

            And here is a sample of my code:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"  layout="absolute" minWidth="955" minHeight="600" creationComplete="init();">

             

                <mx:Script>
                    <![CDATA[
                        import mx.collections.ArrayCollection;
                       
                        [Bindable]private var _comboBoxDataProvider:ArrayCollection;
                       
                        private function init():void {
                           
                            _comboBoxDataProvider = new ArrayCollection();
                            _comboBoxDataProvider.addItemAt('', 0);
                           
                            for(var i:int = 0; i < 6; ++i) {
                                var obj:Object = {};
                                obj.labelField = String(i);
                                _comboBoxDataProvider.addItem(obj);
                            }
                           
                            comboBoxValidator.validate();
                        }
                       
                    ]]>
                </mx:Script>
               
                <mx:StringValidator id="comboBoxValidator"
                    required="true"
                    source="{comboBox}" requiredFieldError="Empty Field Error"
                    property="text"
                    />
               
                <mx:ComboBox  id="comboBox" width="150"
                dataProvider="{_comboBoxDataProvider}"
                labelField="labelField"
                selectedIndex="0"  />
               
            </mx:Application>

            • 4. Re: Using Validator with mx:ComboBox causes it to auto-close
              adamzucchi Level 1

              After doing some digging, the ComboBox closing itself when tied to a StringValidator is a bug that was introduced after Flex 3.2.  If you compile using the 3.2 SDK, all is well, however I am not sure how many of us want to go back that far.

              • 5. Re: Using Validator with mx:ComboBox causes it to auto-close
                JabbyPandaUA Level 3

                I've tried your sample on Flex SDK 3.4 & 3.5, in both cases open combobox does not close when I select the value by the help of the keyboard.

                • 6. Re: Using Validator with mx:ComboBox causes it to auto-close
                  adamzucchi Level 1

                  Hmmmmm....

                   

                  Was this after you had made an initial/valid selection?  For me, this happens only when making a selection via the keyboard from the first, 0 index null state.

                  • 7. Re: Using Validator with mx:ComboBox causes it to auto-close
                    JabbyPandaUA Level 3

                    I open the Combobox list by the mouse interaction and then immediately I start to select the values via keyboard.