RadioButtonGroup inside of Repeater
If you've ever tried to use repeater to create radiobutton groups, you probably found that setting the ID doesn't work and the group won't initialize. That's because flex wants "visual" objects in the repeater. To fix this problem, you simply create the groups before you repeat like so.
<mx:Script>
<![CDATA[
import mx.controls.RadioButtonGroup;
import mx.collections.ArrayCollection;
[Bindable]
private var rbGroups:ArrayCollection;
private function createRBGroups():void{
rbGroups= new ArrayCollection();
var rbGroup:RadioButtonGroup;
for each(var item:Object in someRepeater.dataProvider as ArrayCollection){
rbGroup = new RadioButtonGroup();
rbGroups.addItem(rbGroup);
}
}
]]>
</mx:Script>
<mx:Repeater repeatStart="createRBGroups()" id="someRepeater">
<mx:HBox>
<mx:RadioButton group="{RadioButtonGroup(rbGroups.getItemAt(someRepeater.currentIndex))}"/>
<mx:RadioButton group="{RadioButtonGroup(rbGroups.getItemAt(someRepeater.currentIndex))}"/>
<mx:RadioButton group="{RadioButtonGroup(rbGroups.getItemAt(someRepeater.currentIndex))}"/>
</mx:HBox>
</mx:Repeater>













Comments
It seems to be easier to
It seems to be easier to encapsulate the functionality of the entire RadioButtonGroup in a separate component. Then you can set any variables on the component during the repeater iteration and the issue of handling procedural code within the repeater goes away. We did this internally and it works like a charm. The component extends Box.
good idea
that's a good idea. Sometimes it just doesn't click in my brain to go ahead and make a component.
To access the value you need
To access the value you need to know what position it is at and then do RadioButtonGroup(rbGroups.getItemAt(whateverindex)).selectedValue;
Hope that helps
then how do you access a
then how do you access a value? I tried rbGroups[0].selectedValue and got nothing.