DOC: supporting docs for FormValidationManager

This commit is contained in:
Aaron Carlino 2017-12-13 11:53:18 +13:00
parent 277c129e1e
commit db8a6d71a9

View File

@ -561,15 +561,25 @@ Injector.transform(
(updater) => { (updater) => {
updater.form.addValidation( updater.form.addValidation(
'AssetAdmin.*', 'AssetAdmin.*',
(values, errors) => ({ (values, validator) => {
...errors, if (values.PostalCode.length !== 5) {
PostalCode: values.PostalCode.length !== 5 ? 'Invalid postal code' : null, validator.addError('PostalCode', 'Invalid postal code');
}) }
}
) )
} }
); );
``` ```
The `addValidation()` function takes a callback, with an instance of `FormValidationManager` (`validator` in the above example) as a parameter. `FormValidationMangaer` allows you to manage the validation result using several helper methods, including:
* `addError(fieldName:string, message:string)`
* `addErrors(fieldName:string, messages:Array)`
* `hasError(fieldName:string)`
* `clearErrors(fieldName:string)`
* `getErrors(fieldName:string)`
* `reset(void)`
## Using Injector to customise Redux state data ## Using Injector to customise Redux state data