question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vee-validate scoping for components not working with bootstrap-vue

See original GitHub issue

Versions

  • vee-validate: 2.1.7
  • vue: 2.5.22

Describe the bug Using vee-validate on an application together with bootstrap-vue. Yes, fieldsBagName is changed using:

Vue.use(VeeValidate, { inject: true, fieldsBagName: 'veeFields' });

Having a b-tabs with a component inside each b-tab. Each tab has forms with a common scope. The validation works great inside the component itself but outside using e.g. errors.any('salary'), there is no reaction. If i log errors i can see salary in the result:

{ "vmId": 346, "items": [ { "id": "61", "vmId": 381, "field": "salary.baseSalary_0", "msg": "The salary.baseSalary_0 field is required.", "rule": "required", "scope": "salary" }, { "id": "62", "vmId": 381, "field": "salary.taxTable_0", "msg": "The salary.taxTable_0 field is required.", "rule": "required", "scope": "salary" } ] } Why is this?

using validator.validate() does not trigger the validation inside each component either.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
logaretmcommented, Apr 5, 2019

Sorry for being late to respond, the problem is when using a component based UI library, that the $validator injection will not work properly because the entire component tree can provide their own validator instances. there is a way to resolve that:

  • Disable automatic injection using { inject: false } when configuring vee-validate.
  • Add $_veeValidate config object on the component that will serve as the validation context (or root form), with a validator prop set to 'new'.
  $_veeValidate: {
    validator: "new"
  },

What all of this does, is that it makes the validation context component is the only validator instance provider, forcing the children to only inject from it.

Here is an updated example

This is documented in the same link I provided.

In v3 I will make this much simpler to do.

0reactions
rajesh1211commented, Nov 7, 2019

Thanks @logaretm For this, there was a reason we were using vee-validate 2.0 is this was causing issue with bootstrap vue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vee-validate scoping for components not working ... - GitHub
Using vee-validate on an application together with bootstrap-vue. Yes, fieldsBagName is changed using: Vue.use(VeeValidate, { inject: true, ...
Read more >
How to use vee-validate with bootstrap-vue and TypeScript.
We want to disable it if one or more field contains invalid input. To do this we need to wrap the whole form...
Read more >
vee-validate not working with bootstrap-vue - Stack Overflow
I'm trying to use vee-validate for form validation with bootstrap-vue, and cannot get anything to work. Basically, I want to do:
Read more >
Vee validation is not working inside the <b-form-input> tag ...
Coding example for the question Vee validation is not working inside the tag-Vue.js.
Read more >
How to Validate Form in Vue 3 with VeeValidate - positronX.io
Learn how to create a responsive web form using the BootstrapVue front-end CSS library and validate that Form.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found