2 Replies Latest reply on Sep 13, 2010 8:32 PM by Nirmal Kumar Bhogadi

    Radio Button inside a Repeater

    Nirmal Kumar Bhogadi

      Hello All,

       

      I am generating Radio buttons and buttons inside a repeater component. My requirement is on click of a button, I want to know whether the radio button corresponding to that particular button is selected or not. I am pasting the code below.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                      layout="vertical"
                      >

       

          <mx:Script>
              <![CDATA[
                  import mx.controls.Alert;
                  import mx.collections.ArrayCollection;

       

                  [Bindable]
                  public var savedFilters:ArrayCollection=new ArrayCollection([

       

                      {filterID: "1", label: "Occupied"},
                      {filterID: "2", label: "Un-Occupied"},
                      {filterID: "3", label: "Dont Know"},
                      {filterID: "4", label: "Hello World!!!"}

       

                      ]);

       

                  public function checkLabel(event:Event):void
                  {                 
                             
                              Alert.show("Filter Name: " + event.currentTarget.getRepeaterItem().label);
                             
                  }
              ]]>
          </mx:Script>

       

          <mx:Repeater id="r"
                       dataProvider="{savedFilters}">
              <mx:HBox>
                  <mx:RadioButton id="radio"
                                  label="{r.currentItem.label}"
                                  width="150"
                                  selected="true"
                                />
                  <mx:Button id="loadButton"
                             label="Load"
                             width="100"
                             click="checkLabel(event)"
                             />
              </mx:HBox>

       

          </mx:Repeater>

       

      </mx:Application>

       

       

      Please help me in this respect.

       

      Thanks in advance,

      Nirmal Kumar Bhogadi

        • 1. Re: Radio Button inside a Repeater
          Arun Ganesh Level 3

          Try like this,

          I hope this will help you.

           

          public function checkLabel(radioObj:*):void
                      {                
                                // var repeatItem:*=event.currentTarget.getRepeaterItem();
                                 //Alert.show("Filter Name: " + event.currentTarget.getRepeaterItem().label);
                                 trace(radioObj.selected);
                      }

           

          <mx:Repeater id="r"

           

                           dataProvider="{savedFilters}">

           

                  <mx:HBox>

           

                      <mx:RadioButton id="radio"

           

                                      label="{r.currentItem.label}"

           

                                      width="150"

           

                                      selected="true"

           

                                    />

           

                      <mx:Button id="loadButton"

           

                                 label="Load"

           

                                 width="100"

           

                                 click="checkLabel(radio[event.target.instanceIndices])"

           

                                 />

           

                  </mx:HBox>

           

              </mx:Repeater>

          • 2. Re: Radio Button inside a Repeater
            Nirmal Kumar Bhogadi Level 1

            Perfect, Thanks a lot!!!