views:

1753

answers:

7

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?

A: 

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.

Daniel Brockman
A: 

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

Sorry, but that has to be old code. There's no "selectedRadio" property and events can't be dispatched like that.
Daniel Brockman
A: 

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.

bkildow
Yes, this works in simple test applications. It also works to set selected=false on the selected radio button. But I've run into situations where neither of those two solutions work.I'm sorry to be so vague. I'll see if I can dig up the code and produce a demo when I get back from my vacation.
Daniel Brockman
A: 

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!

online19
A: 

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;" />
darronschall
A: 

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.

Glenn
A: 

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/