vue-form-generator icon indicating copy to clipboard operation
vue-form-generator copied to clipboard

V3 enable custom validators

Open muschottkey opened this issue 5 years ago • 1 comments

  • 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, ...)
  1. Adds support for custom validators

  2. Fixes bugs in validators where errors would occur if we tried to access attributes min, max in field.fieldOptions when it was undefined

  • What is the current behavior? (You can also link to an open issue here)
  1. You can't add custom validators in v3, which is already supported in v2.x.x.

  2. 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 in date, array and string.

  • What is the new behavior (if this is a feature change)?
  1. No more errors for validators
  2. 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.

muschottkey avatar Oct 08 '19 10:10 muschottkey

Coverage Status

Coverage increased (+0.2%) to 74.077% when pulling 8312760856c6b49b25ba4bcaa198653ffdec3e1b on muschottkey:v3-enable-custom-validators into 218bababcdb4dced2fb439d6f6644c23afbf2d16 on vue-generators:v3.

coveralls avatar Oct 08 '19 10:10 coveralls