class Validator
package feathers.validators
extends EventDispatcher
implements IValidator
extended by CreditCardValidator, CurrencyValidator, DateValidator, EmailValidator, NumberValidator, PhoneNumberValidator, RegExpValidator, SocialSecurityValidator, StringValidator, ZipCodeValidator
The Validator class is the base class for all Flex validators. This class implements the ability for a validator to make a field required, which means that the user must enter a value in the field or the validation fails. *
See also:
feathers.events.ValidationResultEvent
Static methods
staticvalidateAll(validators:Array<IValidator>):Array<ValidationResultEvent>
Invokes all the validators in the validators
Array.
Returns an Array containing one ValidationResultEvent object
for each validator that failed.
Returns an empty Array if all validators succeed.
*
Parameters:
validators | An Array containing the Validator objects to execute. * |
---|
Returns:
Array of ValidationResultEvent objects, where the Array contains one ValidationResultEvent object for each validator that failed. The Array is empty if all validators succeed.
Constructor
Variables
enabled:Bool
Setting this value to false
will stop the validator
from performing validation.
When a validator is disabled, it dispatch no events,
and the validate()
method returns null.
*
listener:Dynamic
Specifies the validation listener.
If you do not specify a listener,
Flex uses the value of the source
property.
After Flex determines the source component,
it changes the border color of the component,
displays an error message for a failure,
or hides any existing error message for a successful validation.
property:String
A String specifying the name of the property of the source
object that
contains the value to validate. Setting property
is optional, but if
you specify source
, you should set a value for either property
or
valueFunction
as well.
Reading the property
uses reflection, which may not work if Dead Code
Elimination (DCE) is enabled. The property
property is included for
backwards compatibility with the Flex API, but the new valueFunction
is now recommended instead.
See also:
valueFunction
source:Dynamic
Specifies the object containing the property to validate. Set this to an instance of a component or a data model. You use data binding syntax in MXML to specify the value. This property supports dot-delimited Strings for specifying nested properties.
If you specify a value to the source
property,
then you should specify a value to either the property
property or the valueFunction
property as well.
The source
property is optional.
See also:
property
valueFunction
trigger:IEventDispatcher
Specifies the component generating the event that triggers the validator.
If omitted, by default Flex uses the value of the source
property.
When the trigger
dispatches a triggerEvent
,
validation executes.
triggerEvent:String
Specifies the event that triggers the validation.
If omitted, Flex uses the valueCommit
event.
Flex dispatches the valueCommit
event
when a user completes data entry into a control.
Usually this is when the user removes focus from the component,
or when a property value is changed programmatically.
If you want a validator to ignore all events,
set triggerEvent
to the empty string ("").
valueFunction:() ‑> Dynamic
A function that returns the value to validate. It's recommended to use
valueFunction
instead of property
because reflection is used with
property
, which could result in issues if Dead Code Elimination (DCE)
is enabled.
Methods
validate(?value:Dynamic, suppressEvents:Bool = false):ValidationResultEvent
Performs validation and optionally notifies the listeners of the result.
Parameters:
value | Optional value to validate.
If null, then the validator uses the |
---|---|
suppressEvents | If |
Returns:
A ValidationResultEvent object
containing the results of the validation.
For a successful validation, the
ValidationResultEvent.results
Array property is empty.
For a validation failure, the
ValidationResultEvent.results
Array property contains
one ValidationResult object for each field checked by the validator,
both for fields that failed the validation and for fields that passed.
Examine the ValidationResult.isError
property to determine if the field passed or failed the validation.
See also:
feathers.events.ValidationResultEvent