simple-vue-validator icon indicating copy to clipboard operation
simple-vue-validator copied to clipboard

Feature Request - Validation Scopes

Open stoked74 opened this issue 8 years ago • 2 comments

It would be great if there was a way to provide validation scopes to the validators. This would give the user an easier way to validate groups of form fields. A full form, a form in a dialog/prompt etc. I think it would be more convenient to call $validate('scopeA') and $validate('scopeB') instead of having to define an array of form fields for one-off validations. Not passing any arguments to the $validate() method could validate all of the scopes by default.

I typically have forms with multiple independent dialogs that contain sub forms that need independent validation. I could break them out into their own components and have them validate at the component level, but that's a lot of work for multiple 3-5 input forms that live inside a small dialog.

Scopes could be defined on the validators. Something along the lines of:

validators: {
    scopeA: {
      'submittal.lineNo' (value) {
        return Validator.value(value).required().digit()
      },
      'submittal.description' (value) {
        return Validator.value(value).required().maxLength(1000)
      },
    },
    scopeB: {
      'submittal.specSection' (value) {
        return Validator.value(value).required().maxLength(255)
      },
      'submittal.class' (value) {
        return Validator.value(value).required()
      },
    }
  }

Keep up the great work on the library. It's much appreciated.

stoked74 avatar Jul 20 '17 02:07 stoked74

@stoked74 Thanks for your suggestion, I think this is a very good idea. I would like to implement this in future version, however it will not be very soon as it needs quite a few code changes and testings.

Will keep you posted once I have any progress on this!

semisleep avatar Jul 21 '17 14:07 semisleep

Hasn't this method been implemented yet?

caihuattkl avatar Jan 11 '19 06:01 caihuattkl