Daniel Brockman
Daniel Brockman

Reputation: 19270

In Flex, how do I deselect all radio buttons in a group?

In Flex, sometimes when you need to clear a form you run into the problem that radio button groups seem to defy clearing: try as you might, setting selected=false on all buttons, setting selection=null on the group, doing both, doing them twice, etc., you always seem to end up with one pesky little radio button that's still selected. How do you solve this and restore the radio button group to its initial no-selection state?

Upvotes: 8

Views: 9227

Answers (7)

Aqeel Aslam
Aqeel Aslam

Reputation:

Simply set the selection property of the radioButtonGroup to null and the it'll go to its initial condition.

e.g, if

               <mx:RadioButtonGroup id="answers" />

then writing the following line in ActionScript

                answers.selection = null;

would reset the group with no radio button selected left. Hope it helps you. I took the idea from following link. Best of luck.

http://blog.flexexamples.com/2008/01/06/clearing-a-selected-radiobutton-control-in-flex/

Upvotes: 0

Glenn
Glenn

Reputation: 5342

Obviously the previous answers should get you where you're going in the cleanest way, but if you're hitting your head against the wall, just collect all your radio buttons into a component and then redraw the entire component when you need to clear it. Problem solved.

Forms are gimpy at best anyway. No need to make life too hard.

Upvotes: 0

darronschall
darronschall

Reputation: 859

You need to group all of the radio buttons into a RadioButtonGroup and then set the group selection to null:

<mx:RadioButtonGroup id="myGroup" />

<mx:RadioButton label="One" groupName="myGroup" />
<mx:RadioButton label="Two" groupName="myGroup" />
<mx:RadioButton label="Three" groupName="myGroup" />

<mx:Button label="Clear" click="myGroup.selection = null;" />

Upvotes: 12

online19
online19

Reputation: 125

I believe you are using the RadiobuttonGroup and binding all the radiobutton controls for the perticular group.

So, easy way:

private function radioGroupReset():void

{

radioGroup1.selection = null;

}

This should work!

Upvotes: 0

bkildow
bkildow

Reputation: 5153

You could try setting all of your radio buttons to a RadioButtonGroup then set RadioButtonGroup.selection to null

See http://livedocs.adobe.com/flex/3/langref/mx/controls/RadioButtonGroup.html#includeExamplesSummary for reference on how to implement the RadioButtonGroup control.

Upvotes: 1

yrral
yrral

Reputation: 949

Does this not work?

      function clearRadioSelection(theGroup) {
        theGroup.selection.selected = false;
        theGroup.selectedRadio = undefined;
        theGroup.dispatchEvent({type:"change"});
  }

theGroup is the radio button group (not the individual radio buttons) from: http://kb2.adobe.com/cps/000/c4e4be2f.html

Upvotes: 0

Daniel Brockman
Daniel Brockman

Reputation: 19270

The only way to solve this that I know of is to add a hidden dummy radio button that you select in order to deselect all the others.

Upvotes: 0

Related Questions