218
Creating Custom Validators
The following image shows the class hierarchy for validators:
About overriding the doValidation() method
Your custom validator class must contain an override of the protected
Validator.doValidation()
method that takes a single argument,
value,
of type Object,
and returns an Array of ValidationResult objects. You return one ValidationResult object for
each field that the validator examines and fails the validation. For fields that pass the
validation, you omit the ValidationResult object.
You do not have to create a ValidationResult object for fields that validate successfully. Flex
creates those ValidationResult objects for you.
The base Validator class implements the logic to handle required fields by using the
required
property. When set to
true
, this property specifies that a missing or empty value in a user-
interface control causes a validation error. To disable this verification, set this property to
false
.
In the
doValidation()
method of your validator class, you typically call the base class’s
doValidation()
method to perform the verification for a required field. If the user did not
enter a value, the base class issues a validation error stating that the field is required.
The remainder of the
doValidation()
method contains your custom validation logic.
About the ValidationResult class
The
doValidation()
method returns an Array of
ValidationResult
objects, one for each field
that generates a validation error. The ValidationResult class defines several properties that let
you record information about any validation failures, including the following:
errorCode
A String that contains an error code. You can define your own error codes for
your custom validators.
errorMessage
A String that contains the error message. You can define your own error
messages for your custom validators.
isError
A Boolean value that indicates whether or not the result is an error. Set this property
to
true
.
Validator
All validator classes
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...