Merge pull request #7697 from open-sausages/pulls/4/validate-nine-ten

DOC: Add documentation for FormValidationManager
This commit is contained in:
Robbie Averill 2017-12-17 17:13:22 +13:00 committed by GitHub
commit 2ff0cf7bfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -561,15 +561,25 @@ Injector.transform(
(updater) => {
updater.form.addValidation(
'AssetAdmin.*',
(values, errors) => ({
...errors,
PostalCode: values.PostalCode.length !== 5 ? 'Invalid postal code' : null,
})
(values, validator) => {
if (values.PostalCode.length !== 5) {
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