6 Replies Latest reply: Mar 25, 2008 6:58 AM by dpatterson83 RSS

    Unselect RadioButton

    Mitek17 Community Member

      I am having trouble unselecting the RadioButton, i.e. I've got a RadioButtonGroup & 2 RadioButtons. RadioButtonGroup property selectedValue initially equals null and both buttons are unselected. As soon as I select any RadioButton by mouse click I can't unselect it using selectedValue property.

      Has anybody had the same problem ?

        • 1. Re: Unselect RadioButton
          chris.huston.t10 Community Member
          Assuming your radio button group has an id= RadioButtonGroup, then this will unselect the currently selected radio button.

          RadioButtonGroup.selection.selected = false;

          • 2. Re: Unselect RadioButton
            Mitek17 Community Member

            Originally posted by: Masamune
            RadioButtonGroup.selection.selected = false;

            Thanks, Vygo!

            Btw, is there any way to do this from MXML ?

            • 3. Re: Unselect RadioButton
              chris.huston.t10 Community Member
              You could make a button to unselect your radio group:

              <mx:Button x="165" y="293" label="Unselect" click="RadioButtonGroup.selection.selected = false"/>

              • 4. Re: Unselect RadioButton
                OK, my issue is this, I have a selected radio button and when the user press that button again, I want to unselect it. the problem I am having is that the RadioButtonGroup does not generate an event for me to respond with the unselect. Any ideas?
                • 5. Unselect RadioButton
                  emack06 Community Member
                  OK fellas,

                  I wrote this customized two radio button component that will allow me to unselect the "Selected" radio button just by clicking on it again. Say you click on radiobutton "Yes". Then you click on it again, it will unselect. Please test this and give any feedback to help improve the code. Thanks for your replies in advance:

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Box xmlns:mx=" http://www.adobe.com/2006/mxml" width="118" height="24" direction="horizontal" borderStyle="inset" xmlns:Components="Components.*">

                  import mx.controls.Alert;
                  import mx.events.ItemClickEvent;
                  import flash.events.MouseEvent;

                  var currentSelectionValue:String = null;

                  private function handleClick(event:MouseEvent):void
                  //Just return if the component is disabled
                  if (!enabled) return;

                  if ( event.currentTarget.value == currentSelectionValue )
                  currentSelectionValue = null;
                  event.currentTarget.group.selectedValue = null;
                  currentSelectionValue = event.currentTarget.value;

                  <mx:RadioButtonGroup id="yesNoRadioButton" labelPlacement="right" />
                  <mx:RadioButton label="Yes" id="yesButton" value="Y" groupName="yesNoRadioButton" click="handleClick(event)" />
                  <mx:RadioButton label="No" id="noButton" value="N" groupName="yesNoRadioButton" click="handleClick(event)" width="44"/>
                  <mx:RadioButton id="nullSelection" groupName="yesNoRadioButton" visible="false" width="0" />

                  • 6. Re: Unselect RadioButton
                    emack06: THANK YOU! You had the best answer to my issue, it was simple yet I didn't think of it.