views:

879

answers:

3

iam new to flex , can any one say ,how to validate the radio button is selected or not in flex 3

if my question is wrong ,plz suggest me any thing regarding the validation of radio group

plz help me ...........

A: 

Listen to the itemClick event of the RadioButtonGroup. Within the handler, use selection or selectedValue property to know which RadioButton was clicked.

  • selection - returns a reference to the selected RadioButton instance
  • selectedValue - returns the value property of the selected RadioButton, if it is set. Otherwise, returns its label text.

Both of these properties return null if no RadioButton is selected.

A running example from livedocs

<?xml version="1.0"?>
<!-- Simple example to demonstrate RadioButtonGroup control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;

    <mx:Script>
        <![CDATA[

        import mx.controls.Alert;
        import  mx.events.ItemClickEvent;

        // Event handler function to display the selected button
        // in an Alert control.
        private function handleCard(event:ItemClickEvent):void {
            if (event.currentTarget.selectedValue == "AmEx") {
                    Alert.show("You selected American Express") 
            } 
            else {
                if (event.currentTarget.selectedValue == "MC") {
                    Alert.show("You selected MasterCard") 
                } 
                else {
                    Alert.show("You selected Visa") 
                }
            } 
        }
        ]]>
    </mx:Script>

    <mx:Panel title="RadioButtonGroup Control Example" height="75%" width="75%" 
        paddingTop="10" paddingLeft="10">

        <mx:Label width="100%" color="blue" 
            text="Select a type of credit card."/>

        <mx:RadioButtonGroup id="cardtype" itemClick="handleCard(event);"/>
        <mx:RadioButton groupName="cardtype" id="americanExpress" value="AmEx" 
            label="American Express" width="150" />
        <mx:RadioButton groupName="cardtype" id="masterCard" value="MC" 
            label="MasterCard" width="150" />
        <mx:RadioButton groupName="cardtype" id="visa" value="Visa" 
            label="Visa" width="150" />

    </mx:Panel>        
</mx:Application>
Amarghosh
+1  A: 

this the way i solved the problem ,i any thing wrong please give me the comment

mx:NumberValidator id="radiogroupValidator" source="{radiogroup}" property="selectedValue" allowNegative="false" />

radio group source in mxml file

mx:RadioButtonGroup id="radiogroup" itemClick="radiochangefunction(event)" selectedValue="-1" />

     mx:RadioButton id="radiobtn1" groupName="radiogroup" label="Send Password to existing EmailId" value="0"/>
     mx:RadioButton id="radiobtn2" groupName="radiogroup" label="Enter new EmailId" value="1"/>

funtion for changeradion button

public function radiochangefunction(event):void { radiogroup.selectedValue=event.currentEvent.selectedValue.toString();
}

and finally in the next function

var isValidradiobutton:Boolean = (Validator.validateAll([radiogroupValidator]).length==0);

try this its working

kumar1425
+1  A: 

Simply use a StringValidator:

        <mx:StringValidator id="myRadioButtonGroupValidator" 
        source="{myRadioButtonGroup}" 
        property="selectedValue" 
        required="true"/>
dbasch