vue-form-generator
vue-form-generator copied to clipboard
V3 enable custom validators
- Please check if the PR fulfills these requirements
- [x] The commit message follows our guidelines
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
- What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
-
Adds support for custom validators
-
Fixes bugs in validators where errors would occur if we tried to access attributes
min, max
infield.fieldOptions
when it was undefined
- What is the current behavior? (You can also link to an open issue here)
-
You can't add custom validators in v3, which is already supported in v2.x.x.
-
Some Validators are throwing errors In some validator functions, we were checking the existence of min and max values in the field schema using !isNil(field.fieldOptions.min) and !isNil(field.fieldOptions.max).
However, some fields might have very simple configuration which doesn't include fieldOptions object, meaning that this code will throw an error
TypeError: Cannot read property 'min' of undefined
which vue throws as something like
vue.esm.js:629 [Vue warn]: Error in event handler for "validate-fields": "TypeError: Cannot read property 'min' of undefined"
To guard against this, we need to first make sure that fieldOptions also exists before we try to check whether attributes in it are defined.
This was already present in
number
validator, but was missing indate
,array
andstring
.
- What is the new behavior (if this is a feature change)?
- No more errors for validators
- You can define custom validators when creating the vfg instance, in the same way as it is done in v2.x.x.
- Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?) NO.