5 Replies Latest reply on Sep 1, 2012 7:58 AM by thin_lizzy

    Group radio button itemrenderers of two different lists

    saisri2k2 Level 4

      Hello ,

       

      How do I group radio button item-renderers of two different lists? If i select a radio button of list 1, then the list 2  Radiobutton which was selected previously should be un-selected. How to do?

        • 1. Re: Group radio button itemrenderers of two different lists
          rvollmar

          Hello,

           

          If you have, say, two ArrayCollections, can you create a collectionChange event listener for each?  Then give each piece of data a boolean value such as isSelected.  Create a custom item renderer which contains a RadioButton whose selected property is bound to isSelected.  Then when a RadioButton in one list's item renderer is changed (set to true), that item's isSelected value will get changed, triggering the collectionChange event.  Then the event listener could look for the appropriate object to change in the other ArrayCollection, set its isSelected property to false, and the other list's appropriate RadioButton will update.

           

          I haven't tried it, but that might work.

           

          Rob

          • 2. Re: Group radio button itemrenderers of two different lists
            saisri2k2 Level 4

            Wish that would had worked, but the radio button in a group if set to 'selected' = true through data binding, you manually select, then even if you say selected = false in the data and bind it, that radio button will be still b selected. unless you say radiobuttongroup.selection= null . Only after the above line al the RBs in the group will be unselected

            • 3. Re: Group radio button itemrenderers of two different lists
              Shongrunden Adobe Employee

              Are you looking for something like this:

               

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

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

               

                  <fx:Declarations>

                      <fx:Component className="MyRenderer">

                          <s:ItemRenderer>

                              <s:RadioButton id="rb" label="{data}" group="{outerDocument.rbg}" width="100%" height="100%" />

                          </s:ItemRenderer>

                      </fx:Component>

               

                      <s:RadioButtonGroup id="rbg" />

                  </fx:Declarations>

               

                  <s:List id="myList" itemRenderer="MyRenderer">

                      <s:dataProvider>

                          <s:ArrayList>

                              <fx:String>0</fx:String>

                              <fx:String>1</fx:String>

                              <fx:String>2</fx:String>

                          </s:ArrayList>

                      </s:dataProvider>

                  </s:List>

               

                  <s:List id="myList2" x="150" itemRenderer="MyRenderer">

                      <s:dataProvider>

                          <s:ArrayList>

                              <fx:String>A</fx:String>

                              <fx:String>B</fx:String>

                              <fx:String>C</fx:String>

                          </s:ArrayList>

                      </s:dataProvider>

                  </s:List>

               

              </s:Application>

              • 4. Re: Group radio button itemrenderers of two different lists
                Komal.Mehta

                I also have a similar situation, and that is an interesting code snippet to rescue. But in my case, I am getting the error for "className=MyRenderer", when I try to call it in the List component as itemRenderer="MyRenderer"

                 

                Compiler Error:

                "Definition MyRenderer could not be found."

                 

                Please help.

                 

                thanks,

                Komal

                • 5. Re: Group radio button itemrenderers of two different lists
                  thin_lizzy

                  Nothing like bringing an old thread back to life.

                   

                  Komal, I have this exact same problem.  Oddly enough I can get this code to work in an Air app but the same code does not work in a Flex Mobile app.

                   

                  I cannot get my list itemrenderer to see the radiobuttongroup in my declarations in the Flex Mobile app even if I use outerDocument or if i try to pass it in with data.

                   

                  I've tried with the IR in the declarations, as a separate file and inline in the list, none work.

                   

                   

                  ...still looking for a solution.  If you managed to get this to work please enlighten me.

                   

                  thanks