Versions
Describe the bug
When I inject vee-validate in separate components, it validates all fields from all forms on the page together
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Separate validation for both components
Demo Link
https://codesandbox.io/s/j7yqy3m3p9
or
https://github.com/xorik/vee-validate-inject-bug-demo
Desktop (please complete the following information):
Additional context
Without manual injection everything works perfectly: https://codesandbox.io/s/xvvv436384 (or https://github.com/xorik/vee-validate-inject-bug-demo/commit/b02fc9fb5e8fc2d964259bcc47626fb93a4f0ca9)
Since both have the same validator, validateAll will trigger validation across all fields registered on that validator, this is not a bug. If you want to validate them individually then remove the inject option, or use scopes to group each form errors together.
@logaretm thank you! That helped!
Just one question. In the documentation it said:
$_veeValidate: {
validator: 'new' // give me my own validator scope.
},
So I expect 2 independent scopes for these 2 forms. So I don't quite understand how it works
Actually it isn't so great. I can't use child component with different forms, because I have to hardcode scope now in the template in the errors.has() and errors.first() methods, so I can't reuse child components in different forms
I think you've confused the 2 uses of inject and $_veeValidate options. Your example uses 2 different forms. And uses inject: ['$validator'] so your intent wasn't clear, Each form would better get its own validation scope so you only need:
$_veeValidate: {
validator: 'new' // give me my own validator scope.
}
The inject option will override the new validator and give you the parent instance, causing you to validate other fields.
Here is an updated example that uses the new validator instance given:
@logaretm oh, that's cool, thanks so much!
Most helpful comment
I think you've confused the 2 uses of
injectand$_veeValidateoptions. Your example uses 2 different forms. And usesinject: ['$validator']so your intent wasn't clear, Each form would better get its own validation scope so you only need:The
injectoption will override the new validator and give you the parent instance, causing you to validate other fields.Here is an updated example that uses the new validator instance given:
https://codesandbox.io/s/00wpv7ll7v