As an experiment, I created a RadioButtonGroup validator as a custom validator to determine is a user neglected to select a RadioButton in a RadioButtonGroup:
 
class RBValidator extends mx.validators.Validator {
 
  public function RBValidator () {
   super();
  }
 
  public function doValidation(value) : Void {
   if (value == undefined) {
    validationError("noSelection", "no RadioButton Selected");   
   }
  }
}
 
 
Then used it in a form with a data model. If the user neglects to select a RadioButton, it pops up an Alert box when they click the Button:
 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns:local="*"   >
 
 <mx:Model id="formInfo">
    <SelectedGender>{Gender.selectedData}</SelectedGender>
 </mx:Model>
 
 <local:RBValidator field="formInfo.SelectedGender" listener="this" />
 
        <mx:Form >
            <mx:FormItem label="Select Gender: " >
                <mx:RadioButtonGroup id="Gender"/>
                  <mx:RadioButton id="radio1" label="Male" data="" groupName="Gender" />
                  <mx:RadioButton id="radio2" label="Female" data="" groupName="Gender"/>
 
                <mx:Button label="Check validity"  click="mx.validators.Validator.isValid(this, 'formInfo.SelectedGender');" />
            </mx:FormItem>
        </mx:Form>
 
</mx:Application>
Stephen


From: Dimitrios Gianninas [mailto:[EMAIL PROTECTED]
Sent: Friday, February 25, 2005 5:21 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] form validation

Hi Robert,
 
For part 1, you will have to create your own PhoneNumberValidator class that only validates the value if there is one. I had to do the same thing for some other validator.
 
For part 2, I use the StringValidator for validating ComboBoxes, it should be enough, never done it with radio buttons however.
 
Jimmy Gianninas
Software Developer - Optimal Payments Inc.
 


From: Robert Brueckmann [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 24, 2005 11:10 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] form validation

I’m having a heck of a time understanding how form validation works.  I have a form…it contains text fields, drop down lists, and radio buttons.  It’s a basic user information form…first name, last name, address 1, address 2, etc.  I also have 3 fields: phone, fax, and mobile, but I only have the phone field as being required (visually, anyways, utilizing the required attribute set to true of the mx:FormItem component, but set to false for fax and mobile).  I also have phone, fax and mobile being monitored by the mx:PhoneNumberValidator components.  But the problem is the form won’t submit if the user hasn’t entered a fax or mobile, even though they’re not required but because I have validators on them.  Is there any way to ONLY validate them if the user has entered a value in their fields and not enforce them as being required even though I don’t have them flagged as being required?

 

Also, how do I validate whether a user has selected an option from a drop-down or a radio button group?  I am successfully setting their values to the data model I have set up but do I use a StringValidator on those values to ensure something has been checked or is there a better way to do that?  I looked at the examples in Stephen and Alistair’s book but some things aren’t valid in Flex 1.5 anymore and other things just confuse the heck out of me or don’t apply to the type of form I’m trying to build and validate.

 

Any help on any of these things would be most amazingly appreciated.

 

Thanks!

 

Rob

 

This message contains information from Merlin Securities, LLC, or from one of its affiliates, that may be confidential and privileged. If you are not an intended recipient, please refrain from any disclosure, copying, distribution or use of this information and note that such actions are prohibited. If you have received this transmission in error, please notify the sender immediately by telephone or by replying to this transmission.
Merlin Securities, LLC is a registered broker-dealer. Services offered through Merlin Securities, LLC are not insured by the FDIC or any other Federal Government Agency, are not deposits of or guaranteed by Merlin Securities, LLC and may lose value. Nothing in this communication shall constitute a solicitation or recommendation to buy or sell a particular security.


Reply via email to