How can i validate a radio button in repeater?

How to validate a radio button in a repeater ? all radio buttons are in a radio button group?
All are created dynamically depending on data coming from data base?
anil_fdkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgofmanCommented:
You don't need to validate :)
User can only check or uncheck.
But what you need to add a RadioButtonGroup component outside Repeater and
RadioButtonGroup Id assign to all your RadioButton(s)
I will post my code later.
anil_fdkAuthor Commented:
i have a radio button group , and i am using arraycollection to save the results , tried making custom validator for it, using radiobuttongroup id as source does not work..

      <mx:RadioButtonGroup id="rg"/>
inside repeater
<mx:RadioButton label="Yes" group="{RadioButtonGroup(rbGroups.getItemAt(r.currentIndex))}"                     value="YES"/>
                                    
<mx:RadioButton label="No" group="{RadioButtonGroup(rbGroups.getItemAt(r.currentIndex))}" value="NO"/>

this is the validator....
<validators:RadioButtonGroupValidator id="vRG"
  source="{rg}" property="selectedValue" required="true" />


i am sending code for validator attached if u need to see it. RadioButtonGroupValidator.as
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

dgofmanCommented:
You don't need to use array of Radio!uttonGroup(s)
Should be only one component.
Check my solution Q_26884775 you have similar implemenation.
anil_fdkAuthor Commented:
well its the same question, just want to validate that every question has been answered and no field is empty..I am same guy with the questionnaire
dgofmanCommented:
Nice to see you again.
Ok, send me more details about you problem.
anil_fdkAuthor Commented:
well same here , gud 2 c u 2.......i have to save the input of the questionnaire, and check before that all questions have been answered. if any one is missing, we have to highlight it as red (as a validator). Want to add a validator like functionality in there.
anil_fdkAuthor Commented:
dgofmanCommented:
It's so complicated from your link, I just updated my function to handle your problem

import mx.controls.RadioButton;
private function submit():void {
	var options:Array = [];
	var valid:Boolean = true;
	for(var i:uint = 0; i < listData.length; i++){
		var item:Object = listData[i];
		var str:String = label[i].text;
		var rb:RadioButton = no_rb[i] as RadioButton;
		rb.errorString = "";
		if( yes_rb[i].selected == false &&
			no_rb[i].selected == false){
			valid = false;
			rb.errorString = "Please select an answer for this question";
		}
		if(item.type == 'radio'){
			options.push(str + "="+ (yes_rb[i].selected ? "YES" : "NO"));
		}else{
			options.push(str + "="+ info[i].text);
		}
	}
	if(valid == true)
		Alert.show(options.join("\n"));
}

Open in new window

anil_fdkAuthor Commented:
Can u specify yes_rb[] & no_rb_[]. Thanks a ton for your help..
dgofmanCommented:
I will recommend by default add selected=true for Yes or No radio button,
In this case forget about validating user never will able to uncheck.
Nice and clean.

<mx:RadioButton id="yes_rb" label="Yes" groupName="group{r.currentIndex}"/>
<mx:Spacer width="5"/>
<mx:RadioButton id="no_rb" label="No" groupName="group{r.currentIndex}" selected="true"/>
anil_fdkAuthor Commented:
i am using error string function for validation, but i have a small problem in that. the radiobuttons are working fine,they do change color to red and show error message if they are not answred but i am tryin to use same method on text Area, but text area does not show the red border , though it shows the error message. Can you tell me y it is acting weirdly?  
dgofmanCommented:
It's work for me

<?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" initialize="init()"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
      <mx:TextArea errorString="This is error string"/>
</s:Application>
anil_fdkAuthor Commented:
Well its working fine in fb plug in  but when i do include it in my project , color of the text area is not changing , even if i try setStyle , still color for text area border wont change.
Can i use string validator in a repeater???? can u guide me thriuogh
dgofmanCommented:
I can see your TextArea working well in the Repeater too

import mx.controls.RadioButton;
private function submit():void {
	var options:Array = [];
	var valid:Boolean = true;
	for(var i:uint = 0; i < listData.length; i++){
		var item:Object = listData[i];
		var str:String = label[i].text;
		if(item.type == 'radio'){
			var rb:RadioButton = no_rb[i] as RadioButton;
			rb.errorString = "";
			if( yes_rb[i].selected == false &&
				no_rb[i].selected == false){
				valid = false;
				rb.errorString = "Please select an answer for this question";
			}
			options.push(str + "="+ (yes_rb[i].selected ? "YES" : "NO"));
		}else{
			info[i].errorString = "";
			if(info[i].text == "")
				info[i].errorString = "Please add your comments";
			options.push(str + "="+ info[i].text);
		}
	}
	if(valid == true)
		Alert.show(options.join("\n"));
} 

Open in new window

dgofmanCommented:
I forgot to vet validation flag to true if string is empty

info[i].errorString = "";
if(info[i].text == ""){
	info[i].errorString = "Please add your comments";
	valid = false;
}

Open in new window

anil_fdkAuthor Commented:
well if i include everthing in my project problem is still there, but if we do run it alone in FB, it works fine, well thanks a ton for the help .I do not know, i am not able to use setstyle either to change border color?????
dgofmanCommented:
you can customize border using setStyle or CSS or override Skin implementation

check package mx.skins.halo  class HaloBorder.as in SDK

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Flex

From novice to tech pro — start learning today.