RadioButtonGroup inside of Repeater
Submitted by jrowny on Wed, 10/22/2008 - 07:00
See the Update before you look at this.
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>
Bookmark/Search this post with:
It seems to be easier to
Submitted by Rob (not verified) on Mon, 09/28/2009 - 01:15.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
Submitted by jrowny on Thu, 11/19/2009 - 14:04.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
Submitted by Jonathan Rowny (not verified) on Tue, 02/17/2009 - 06:45.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
Submitted by Anonymous (not verified) on Tue, 02/17/2009 - 05:39.then how do you access a value? I tried rbGroups[0].selectedValue and got nothing.