Hi, I am trying to do something similar in Flex 3 (old code that I am maintaining). In Flex3 what is the equivalent of ToggleButtonBase where I can check the selected property?
Thanks KS --- In [email protected], "mregert@..." <michael_regert@...> wrote: > > Full source if this helps: > ------------------------------ > Validation.mxml > > > <?xml version="1.0" encoding="utf-8"?> > <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" > xmlns:s="library://ns.adobe.com/flex/spark" > xmlns:mx="library://ns.adobe.com/flex/mx" > xmlns:local="*" > minWidth="955" minHeight="600" > backgroundColor="#DDEFFF" > creationComplete="creationCompleteHandler(event)" > > > <fx:Script> > <![CDATA[ > import mx.events.FlexEvent; > > private var checkboxes:Array; > > protected function > creationCompleteHandler(event:FlexEvent):void > { > checkboxes = new Array(); > checkboxes.push(ckbxA); > checkboxes.push(ckbxB); > checkboxes.push(ckbxC); > } > > > protected function > button1_clickHandler(event:MouseEvent):void > { > checkBoxValidator.validate(checkboxes); > } > > ]]> > </fx:Script> > <fx:Declarations> > <local:SelectionValidator id="checkBoxValidator" > > property="checkboxes" > > listener="{bc}"/> > </fx:Declarations> > <s:HGroup id="hg" > horizontalCenter="0" verticalCenter="0" > verticalAlign="middle" > paddingLeft="10" paddingRight="10" > paddingTop="5" paddingBottom="5"> > > <s:BorderContainer id="bc" > minHeight="10" > contentBackgroundAlpha="0.0" > backgroundAlpha="0.0" > > borderVisible="{bc.errorString != ''}"> > <s:layout> > <s:HorizontalLayout gap="20" > > paddingLeft="10" paddingRight="10" > > paddingTop="5" paddingBottom="5" > > verticalAlign="middle" /> > </s:layout> > > <s:CheckBox id="ckbxA" label="CheckBox A"/> > <s:CheckBox id="ckbxB" label="CheckBox B"/> > <s:CheckBox id="ckbxC" label="CheckBox C"/> > </s:BorderContainer> > > <s:Label text="Some User Input:" paddingTop="3"/> > <s:TextInput id="tiUserInput"/> > <s:Button label="Test Validation" > click="button1_clickHandler(event)"/> > </s:HGroup> > </s:Application> > > -------------------------------------- > SelectionValidator.as > > package > { > import mx.validators.ValidationResult; > import mx.validators.Validator; > > import spark.components.supportClasses.ToggleButtonBase; > > /** > * A custom validator that takes an input array of objects that can > * be selected (checkboxes for example), and validates that at least > * one of them has been selected. > */ > public class SelectionValidator extends Validator > { > public function SelectionValidator() > { > super(); > } > > override protected function doValidation(value:Object):Array { > //validate super > var errorArray:Array = super.doValidation(value); > > //return if there are already errors > if(errorArray.length > 0) { > return errorArray; > } > > //no further validation if length == 0 > if((value as Array).length == 0) { > return new Array(); > } > > var minSelected:Boolean = false; > for each (var selectionObject:ToggleButtonBase in > value) { > if (selectionObject.selected == true) { > // One is selected, so return success > minSelected = true; > break; > } > } > if (minSelected) { > return new Array(); > } else { > errorArray.push(new ValidationResult(true, > null, "", "At least one checkbox must be selected.")); > return errorArray; > } > > return errorArray; > } > } > } >

