| Package | org.granite.validation |
| Class | public class FormValidator |
| Inheritance | FormValidator mx.validators.Validator |
FormValidator class is Flex utility that simplifies
the validation framework usage with input components. It performs
validation on the fly whenever the user enters data into graphical
inputs and automatically displays error messages when these data are
incorrect, based on constraint annotations placed on bean properties.
[Bindable]
public class Person {
[Size(max="10")]
public var firstname:String;
[NotNull] [Size(min="2", max="10")]
public var lastname:String;
}
<fx:Declarations>
<v:FormValidator id="fValidator" form="{personForm}" entity="{person}"/>
</fx:Declarations>
<fx:Script>
[Bindable]
protected var person:Person = new Person();
protected function savePerson():void {
if (fValidator.validateEntity()) {
// actually save the validated person entity...
}
}
protected function resetPerson():void {
person = new Person();
}
</fx:Script>
<mx:Form id="personForm">
<mx:FormItem label="Firstname" required="true">
<s:TextInput text="@{person.firstname}"/>
</mx:FormItem>
<mx:FormItem label="Lastname" required="true">
<s:TextInput text="@{person.lastname}"/>
</mx:FormItem>
</mx:Form>
<s:Button label="Save" click="savePerson()"/>
<s:Button label="Cancel" click="resetPerson()"/>
| Property | Defined by | ||
|---|---|---|---|
| entity : Object
The entity, with constraint annotations, to be validated.
| FormValidator | ||
| entityPath : String = "null"
The path of the entity to be used when the entity which will be validated
is not the root of the bindings.
| FormValidator | ||
| form : Object
The form component that contains inputs bound to the entity properties
(may be a
Form or any other Container
subclass). | FormValidator | ||
| groups : Array = null
The validation groups to be used, as an array of
Class
names. | FormValidator | ||
| prioritaryComponentProperties : Array [static]
Array of property names that will be considered prioritarity as candidates for UI input bindings.
| FormValidator | ||
| unhandledViolationsMessage : String [read-only]
A message containing all unhandled violations messages, separated by
new lines.
| FormValidator | ||
| validateOnChange : Boolean = true
Should validation be done on the fly? Otherwise, validation will be
only done when an input loses focus.
| FormValidator | ||
| validatorFactory : ValidatorFactory
The
ValidatorFactory to be used in the validation
process (initialized with the the default instance). | FormValidator | ||
| Property | Defined by | ||
|---|---|---|---|
| actualListeners : Array [read-only]
| FormValidator | ||
| _id : String | FormValidator | ||
| Method | Defined by | ||
|---|---|---|---|
|
getUnhandledViolations():Array
Returns the unhandled violations of the last global validation
as an array of
ConstraintViolations. | FormValidator | ||
|
getViolations():Array
Returns the result of the last global validation as an array of
ConstraintViolations. | FormValidator | ||
|
validateEntity():Boolean
Validate the underlying entity instance for the currently set groups.
| FormValidator | ||
| Method | Defined by | ||
|---|---|---|---|
|
doValidation(value:Object):Array
| FormValidator | ||
|
handleResults(errorResults:Array):ValidationResultEvent
| FormValidator | ||
| Event | Summary | Defined by | ||
|---|---|---|---|---|
Dispatched when validation is done, with a (possibly empty) array
of ValidationResult for any ConstraintViolation
that couldn't be associated with any input. | FormValidator | |||
| Constant | Defined by | ||
|---|---|---|---|
| UNHANDLED_VIOLATIONS : String = "unhandledViolations" [static]
| FormValidator | ||
| actualListeners | property |
actualListeners:Array [read-only]Implementation
protected function get actualListeners():Array
| entity | property |
entity:Object [read-write]
The entity, with constraint annotations, to be validated. This entity
must implement the IEventDispatcher interface, explicitly
or not (ie: annotated with [Bindable]).
This property can be used as the source for data binding.
Implementation public function get entity():Object
public function set entity(value:Object):void
| entityPath | property |
public var entityPath:String = "null"The path of the entity to be used when the entity which will be validated is not the root of the bindings.
| form | property |
form:Object [read-write]
The form component that contains inputs bound to the entity properties
(may be a Form or any other Container
subclass).
This property can be used as the source for data binding.
Implementation public function get form():Object
public function set form(value:Object):void
| groups | property |
public var groups:Array = null
The validation groups to be used, as an array of Class
names. Default is null, meaning that the Default group
will be used.
| _id | property |
protected var _id:String
| prioritaryComponentProperties | property |
public static var prioritaryComponentProperties:ArrayArray of property names that will be considered prioritarity as candidates for UI input bindings. Can be used to disambiguate some cases where the component cannot reliably determine which property holds the binding. Values can be added/removed by the user is necessary.
| unhandledViolationsMessage | property |
unhandledViolationsMessage:String [read-only]A message containing all unhandled violations messages, separated by new lines.
This property can be used as the source for data binding.
Implementation public function get unhandledViolationsMessage():String
| validateOnChange | property |
public var validateOnChange:Boolean = trueShould validation be done on the fly? Otherwise, validation will be only done when an input loses focus. Default is true.
| validatorFactory | property |
public var validatorFactory:ValidatorFactory
The ValidatorFactory to be used in the validation
process (initialized with the the default instance).
| doValidation | () | method |
protected override function doValidation(value:Object):ArrayParameters
value:Object |
Array |
| getUnhandledViolations | () | method |
public function getUnhandledViolations():Array
Returns the unhandled violations of the last global validation
as an array of ConstraintViolations. Unhandled violations
are violations that couldn't be associated to any input during the
last global validation (thus, they couldn't be displayed anywhere).
Array — the unhandled violations of the last global validation
as an array of ConstraintViolations.
|
| getViolations | () | method |
public function getViolations():Array
Returns the result of the last global validation as an array of
ConstraintViolations.
Array — the result of the last global validation as an array of
ConstraintViolations.
|
| handleResults | () | method |
protected override function handleResults(errorResults:Array):ValidationResultEventParameters
errorResults:Array |
ValidationResultEvent |
| validateEntity | () | method |
public function validateEntity():BooleanValidate the underlying entity instance for the currently set groups.
ReturnsBoolean — true if validation succeeds, false
otherwise.
|
| unhandledViolations | event |
mx.events.ValidationResultEvent
Dispatched when validation is done, with a (possibly empty) array
of ValidationResult for any ConstraintViolation
that couldn't be associated with any input.
See also
| UNHANDLED_VIOLATIONS | constant |
public static const UNHANDLED_VIOLATIONS:String = "unhandledViolations"