17 Replies Latest reply on Oct 26, 2009 5:02 PM by Peter deHaan

    Flex beta 2 - ComboBox not working

    teocomi

      it seems like ComboBoxes are not working with sdk 4.0.0.10485; while they were with 4.0.0.7219

      i simply click and nothing happens..

       

      code is this:

          <mx:ComboBox>
              <mx:ArrayCollection>
                  <fx:String>AK</fx:String>
                  <fx:String>AL</fx:String>
                  <fx:String>AR</fx:String>
              </mx:ArrayCollection>       
          </mx:ComboBox>

       

      but also using other kind of dataProviders it's the same..

      am i mistaken?

       

      Thanks!

        • 1. Re: Flex beta 2 - ComboBox not working
          teocomi Level 1

          the dropdownlist instead works proprely..

          • 2. Re: Flex beta 2 - ComboBox not working
            kingquattro Level 1

            I second this issue.  I have a comboBox that whose data is fetched from DB based on another combo box selection. I get right data fetched, and then using combobox.dataprovider = Arraycollection to update the values, the assignment is done without any errors, but the change is not displayed on the web.  Except when I click on one of the selection in the combo box, only then I see the data changed, other wise the data see is the old one.

             

            Jay

            • 3. Re: Flex beta 2 - ComboBox not working
              David_F57 Level 5

              Hi,

              Maybe i'm not understanding the problem, but if I populate a combobox with an initial index set to 0 the box displays correctly if I change the value associated grids or labels change correctly.

               

              David

               

              this is a basic example

              http://gumbo.flashhub.net/combo/

               

               

              I forgot to attach the code to the example so here it is

               

              <?xml version="1.0" encoding="utf-8"?>

              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

              xmlns:s="library://ns.adobe.com/flex/spark"

              xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768">

              <fx:Script>

              <![CDATA[

              import mx.collections.ArrayCollection;

               

              [Bindable] private var myData:ArrayCollection= new ArrayCollection([

              {Key:1,state:'ACT',name:'Australian Capital Territory'},

              {Key:2,state:'NSW',name:'New South Wales'},

              {Key:3,state:'NT',name:'Northern Territory'},

              {Key:4,state:'QLD',name:'Queensland'},

              {Key:5,state:'SA',name:'South Australia'},

              {Key:6,state:'TAS',name:'Tasmania'},

              {Key:6,state:'WA',name:'Western Australia'},

              {Key:7,state:'VIC',name:'Victoria'}]);

               

              ]]>

              </fx:Script>

               

              <mx:ComboBox id="cb" x="161" y="82" editable="true" selectedIndex="0" dataProvider="{myData}" labelField="state"/>

               

              <mx:DataGrid id="dg" x="161" y="143" width="369" height="157" dataProvider="{myData}"  selectedIndex="{cb.selectedIndex}">

              <mx:columns>

              <mx:DataGridColumn headerText="ID" dataField="Key"/>

              <mx:DataGridColumn headerText="State" dataField="state"/>

              <mx:DataGridColumn headerText="Name" dataField="name"/>

              </mx:columns>

              </mx:DataGrid>

              <s:Label x="352" y="86" text="{myData[cb.selectedIndex].state}" width="100" height="12"/>

              <s:Label x="463" y="87" text="{myData[cb.selectedIndex].name}" width="100" height="12"/>

              </s:Application>

              • 4. Re: Flex beta 2 - ComboBox not working
                kingquattro Level 1

                umm, well I think I haven't done a good job of explaining the situation, sorry, let me try again.

                 

                I have a form view, initially combo box A is populated, and combo box B is empty.  When user selects something in A, a close event is dispatched, and based on the A.selectedItem.data, a cfc fetch's data from db and an ArrayCollection is returned which is set as B.dataprovider and all data is seen as expected in B

                 

                So far as expected. 

                 

                Now if user selects another value in A, a cfc fetch's and B.dataprovider is set again.  Here the data is not updated, I still see results from previous selection of A.  But if I select any value in B, then and only then does the data for B is show correctly i.e result from second selection of A.  I am using B.validateNow() every time b.dataprovider is executed.

                 

                Hope this helps

                 

                Jay

                • 5. Re: Flex beta 2 - ComboBox not working
                  David_F57 Level 5

                  Ok, so the initial post seemed to have an issue with the combobox not selecting which seems more a coding issue as I can't replicate an issue with a combobox ignoring selection. in the case of 'a' populating 'b' and 'b' populating a form the only thing I can think of is that unless the selected index on b is reset after the data is changed b's form will remain unchanged and b itself maybe sitting on a selected index of -1 due to the list being invalidated during the data change process.

                   

                  Just a thought , if I have a bit of time I will setup something (php as I don't use coldfusion) and see if I get a similar issue.

                   

                  David

                  • 6. Re: Flex beta 2 - ComboBox not working
                    Peter deHaan Level 4

                    @kingquattro,

                     

                    Can you post a bit of code? Are you listening for a close event, or a change event on the ComboBox?

                     

                    Peter

                    • 7. Re: Flex beta 2 - ComboBox not working
                      kingquattro Level 1

                      sure I should have done that in earlier sorry.

                       

                      here it is the snippet

                       

                      var _tempLibId:Number = -1;

                       

                      protected function getlibReq(v:Number):void{

                      libraryRequest.token=Library.getLibraryObject(env_item.selectedItem.data);

                      _tempLibId=v;

                      }

                       

                      protected function libraryResponse(event:ResultEvent):void{

                           var ac:ArrayCollection = event.result as ArrayCollection;

                       

                           lib_item.dataProvider = ac;

                           lib_item.selectedIndex=0;

                           lib_item.validateNow();

                       

                           for (var i:int=0;i<ac.length; i++)

                      if (ac.getItemAt(i).data == _tempLibId)

                            lib_item.selectedIndex=i;

                      }

                       

                      .....

                       

                      <mx:FormItem label="Environment" id="env_label" required="true">

                      <mx:ComboBox id="env_item" close="getlibReq(-1)"/>

                      </mx:FormItem>

                      <mx:FormItem label="Library" id="lib_label" required="false">

                      <mx:ComboBox id="lib_item"/>

                      </mx:FormItem>

                       

                       

                      In each of the combo box I always have my first value as "Select One" with value of -1.

                       

                      You can see a working copy of this issue at

                       

                      http://virome.dbi.udel.edu/VIROME/VIROME.html#view=2;

                       

                      If you select "Environment" library combo box will change which is initially empty.  Next you change "Environment" again and you will see the problem arise.

                       

                      Thank you

                      Jay

                      • 8. Re: Flex beta 2 - ComboBox not working
                        David_F57 Level 5

                        Ok,  it looks like you pass -1 to your data request routine then use -1 to find a position in the second combobox this would mean you would always get the same result, which if i read the logic right woud be a fail every time As no matter what you select you search for -1 which I am assuming is not data but an index number.

                         

                        David.

                        • 9. Re: Flex beta 2 - ComboBox not working
                          Peter deHaan Level 4

                          Also, I would use the change event and not the close event.

                          (a) It is possible to open/close a ComboBox and not change the selected value (so you'd be doing a whole CFC call for nothing).

                          (b) It is possible to change the selected ComboBox value without opening the dropdown (pressing up/down when the ComboBox button has focus), and in this case you'd never call your CFC to change the related value.

                           

                          Also, if you could send all the related data as XML, you could try something like this which wouldn't require you to call CFCs whenever the ComboBox values are changed; http://blog.flexexamples.com/2007/08/04/creating-two-related-comboboxes/

                           

                          Peter

                          • 10. Re: Flex beta 2 - ComboBox not working
                            David_F57 Level 5

                            definitely pay a visit to Peters blog site and spend a bit of time going through his examples its the best FB4 reference link you could add to your browser.

                             

                            Also I would be inclined to attach your dataprovider in the combobox declaration and not redeclare the array or reattach it each time you do a request. If you feel the urge you can always clear the array before repopulating it with new data(although you don't need to).

                            • 11. Re: Flex beta 2 - ComboBox not working
                              kingquattro Level 1

                              OK so here is something really strange. 

                               

                              I tried the simplest case

                               

                              <fx:Script>

                              ....

                              [Bindable] private var _libs:ArrayCollection = new ArrayCollection();

                               

                              protected function getlibReq():void{

                              libraryRequest.token=Library.getLibraryObject(env_item.selectedItem.data);

                              }

                               

                              protected function libraryResponse(event:ResultEvent):void{

                              _libs = event.result as ArrayCollection;

                              }

                              ....

                              </fx:Script>

                               

                              <mx:FormItem label="Environment" id="env_label" required="true">

                              <mx:ComboBox id="env_item" change="getlibReq()"/>

                              </mx:FormItem>

                              <mx:FormItem label="Library" id="lib_label" required="false">

                              <mx:ComboBox id="lib_item" dataProvider="{_libs}"/>

                              </mx:FormItem>

                               

                              Still If I select a environment, and then WITHOUT any selection (I just view the values and close it) in library combo box I select another environment, and then I open the combo box again, the value are from previous environment selection, but If I select one value in library combo box, values are changed.

                               

                              BUT if I select an environment, and then SELECT a value in library combo box which is a value other than the first one.  Then go back to environment

                              combo box and select a new value, all values in library combo box change, and are displayed properly.

                               

                              This is strange.  Its seem that the library combo box does not get rendered with proper data unless a change even occurs in that box, but in my code I am never listening for or dispatch a change event for library combo box only for environment combo box.

                               

                              here is what my sample data for env and lib combo box look like

                               

                              env array collection:

                                   arr[0].label="Select One"

                                           data="-1"

                                   arr[1].label = "Water"

                                           data = "1"

                                   arr[2].label = "Soil"

                                             data="2"

                               

                              lib array collection:

                                   arr[0].label="Select One"

                                             data="-1"

                                   arr[1].label="CBAY"

                                             data="1"

                                   arr[2].label="MBS"

                                             data="2"

                              ...

                              • 12. Re: Flex beta 2 - ComboBox not working
                                David_F57 Level 5

                                ok, round 10,

                                 

                                this last round triggered my memory about a caching issue in lists that was resolved about 2 months ago its starting to smell a little like that so I need to do a search in jira and see if it is the same thing. In the mean time this is using the spark component, see if it gets closer to what you are chasing.

                                (it only works for item 1 and item 2 - i'm lazy )

                                 

                                David.

                                 

                                <?xml version="1.0" encoding="utf-8"?>

                                <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                                xmlns:s="library://ns.adobe.com/flex/spark"

                                xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" creationComplete="appInit()">

                                <fx:Script>

                                <![CDATA[

                                import spark.events.IndexChangeEvent;

                                import mx.collections.ArrayCollection;

                                 

                                [Bindable] private var myStates:ArrayCollection= new ArrayCollection([

                                {Key:1,state:'ACT',name:'Australian Capital Territory'},

                                {Key:2,state:'NSW',name:'New South Wales'},

                                {Key:3,state:'NT',name:'Northern Territory'},

                                {Key:4,state:'QLD',name:'Queensland'},

                                {Key:5,state:'SA',name:'South Australia'},

                                {Key:6,state:'TAS',name:'Tasmania'},

                                {Key:6,state:'WA',name:'Western Australia'},

                                {Key:7,state:'VIC',name:'Victoria'}]);

                                 

                                [Bindable] private var myACT:ArrayCollection= new ArrayCollection([

                                {Key:1,state:'ACT',name:'Kingston'},

                                {Key:2,state:'ACT',name:'Manuka'},

                                {Key:3,state:'ACT',name:'Narrabundah'},

                                {Key:4,state:'ACT',name:'RedHill'}]);

                                 

                                [Bindable] private var myNSW:ArrayCollection= new ArrayCollection([

                                {Key:1,state:'NSW',name:'Cronulla'},

                                {Key:2,state:'NSW',name:'Gymea'},

                                {Key:3,state:'NSW',name:'Miranda'},

                                {Key:4,state:'NSW',name:'Yowie Bay'}]);

                                 

                                [Bindable] private var myInfo:ArrayCollection= new ArrayCollection();

                                 

                                private function appInit(): void

                                {

                                myInfo=myACT;

                                }

                                 

                                protected function cb1_changeHandler(event:IndexChangeEvent):void

                                {

                                switch(cb1.selectedIndex)

                                {

                                case 0: myInfo=myACT;

                                break;

                                case 1: myInfo=myNSW;

                                break;

                                }

                                cb2.selectedIndex=-1;

                                }

                                ]]>

                                </fx:Script>

                                <s:DropDownList id="cb1" x="37" y="97" dataProvider="{myStates}" change="cb1_changeHandler(event)" labelField="name" width="180" prompt="select something" enabled="true" selectedIndex="-1"></s:DropDownList>

                                <s:DropDownList id="cb2" x="249" y="97" labelField="name" width="180" dataProvider="{myInfo}" prompt="select something" selectedIndex="-1" enabled="true"></s:DropDownList>

                                </s:Application>

                                • 13. Re: Flex beta 2 - ComboBox not working
                                  Peter deHaan Level 4

                                  One other thing, when resetting the data provider, try setting the  lib_item data provider's index to -1 as well and see if that makes a difference:

                                   

                                  protected function libraryResponse(event:ResultEvent):void{

                                      _libs = event.result as ArrayCollection;

                                      lib_item.selectedIndex = -1;

                                  }

                                   

                                  Peter

                                  • 14. Re: Flex beta 2 - ComboBox not working
                                    kingquattro Level 1

                                    Hey guys,

                                       Spark DropDownList works just fine.  But the mx:ComboBox does not work still issue with caching, I have even tried to set the selectedIndex to -1, even tried to make multiple selectedIndex statements in the hopes of simulation a change event, but that does not help either.  any one know how to make a spark drop down list look just like the halo combo box?  I did few search and didn't find any thing about it.

                                     

                                    Thanks

                                    Jay

                                    • 15. Re: Flex beta 2 - ComboBox not working
                                      David_F57 Level 5

                                      Hi,

                                       

                                      You can skin the component, if you right click on the spark component there is an option to copy the default skin. That will give you a new skinclass which you can then modify so that it looks more like the halo control.

                                       

                                      David.

                                      • 16. Re: Flex beta 2 - ComboBox not working
                                        Peter deHaan Level 4

                                        @kingquattro,

                                         

                                        I'm not sure why it would work with Spark DropDownList but not the Spark/Halo ComboBox control.

                                         

                                        Can you please file a bug at http://bugs.adobe.com/flex/ and include your source code and somebody at Adobe can investigate further.

                                         

                                        Thanks,

                                        Peter

                                        • 17. Re: Flex beta 2 - ComboBox not working
                                          Peter deHaan Level 4

                                          Scratch that. Alex Harui sent me a simple test case showing the issue and I've filed it at http://bugs.adobe.com/jira/browse/SDK-23838

                                           

                                          Please feel free to add your comments (or vote/subscribe) to the bug.

                                           

                                          Thanks,

                                          Peter