$validator is undefined when using inject: false for child components that are inside a
It seems injection works on the first child in the hierarchy, but doesn't work on deeper children.
Shouldn't you also inject the validator on the items component, since the item component requests it, but its parent items doesn't provide it because it doesn't have its own instance for it.
It would be possible in the JSFiddle, but in my real app, items component comes from a dependency so I can't add the injection code for it.
I think it should just traverse the component tree up until it finds a validator.
I have found the issue here : https://github.com/logaretm/vee-validate/blob/master/src/mixin.js#L7-L11
mixin.provide = function providesValidator() {
return {
$validator: this.$validator
};
};
Problem is that when this.$validator is undefined, it actually inject in the component with an undefined value.
It should be fixed with the following
mixin.provide = function providesValidator() {
if (this.$validator) {
return {
$validator: this.$validator
};
}
};
Then, it behaves like manually provided value (dummy in the JSFiddle) and VueJS traverse the tree component up until in finds a $validator instance. I just tested this change in my app and it fix my issue.
I see, I didn't take that into account. Thanks!
Most helpful comment
I have found the issue here : https://github.com/logaretm/vee-validate/blob/master/src/mixin.js#L7-L11
Problem is that when
this.$validatoris undefined, it actually inject in the component with an undefined value.It should be fixed with the following
Then, it behaves like manually provided value (
dummyin the JSFiddle) and VueJS traverse the tree component up until in finds a $validator instance. I just tested this change in my app and it fix my issue.