Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 223

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

You can implement the NameValidator class, as the following example shows:
package myValidators
{
import mx.validators.Validator;
import mx.validators.ValidationResult;
public class NameValidator extends Validator {
// Define Array for the return value of doValidation().
private var results:Array;
public function NameValidator () {
super();
}
override protected function doValidation(value:Object):Array {
var fName:String = value.first;
var mName:String = value.middle;
var lName:String = value.last;
// Clear results Array.
results = [];
// Call base class doValidation().
results = super.doValidation(value);
// Return if there are errors.
if (results.length > 0)
return results;
// Check first name field.
if (fName == "" || fName == null) {
results.push(new ValidationResult(true,
return results;
}
// Check middle name field.
if (mName == "" || mName == null) {
results.push(new ValidationResult(true,
return results;
}
// Check last name field.
if (lName == "" || lName == null) {
results.push(new ValidationResult(true,
return results;
}
"first", "noFirstName", "No First Name."));
"middle", "noMiddleName", "No Middle Name."));
"last", "noLastName", "No Last Name."));
Example: Validating multiple fields
223

Advertisement

Table of Contents
loading

Table of Contents