mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #7697 from open-sausages/pulls/4/validate-nine-ten
DOC: Add documentation for FormValidationManager
This commit is contained in:
commit
2ff0cf7bfb
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user