Unable to validate child components
See original GitHub issueVersions
- vee-validate: 2.1.0-beta2
- vue: 2.5.2
Describe the bug I have an application with several child components all of which have
inject: ['$validator']
the parent’s code is this:
<template>
<form id="myform">
<CompA />
<CompB />
<CompC />
<CompD />
</form>
</template>
<script>
import { eventBus } from '@/main'
const CompA = () => import('@/components/CompA')
const CompB = () => import('@/components/CompB')
const CompC = () => import('@/components/CompC')
const CompD = () => import('@/components/CompD')
export default {
name: 'MyForm',
inject: ['$validator'],
data() {
return {
}
},
components: {
CompA,
CompB,
CompC,
CompD
},
methods: {
submit() {
this.$children.forEach(vm => {
console.log(vm.$options._componentTag)
vm.$validator.validateAll().then(result => {
if (!result) {
console.log('el: '+ vm.$validator.errors.items[0].field)
this.$el.querySelector('#' + vm.$validator.errors.items[0].field).scrollIntoView(false)
}
}).catch((err) => {
console.log('error: ' + err)
})
})
}
}
}
</script>
The _componentTag is correct in that it detects components A through D but the problem is that the validation is only working on the element of CompD. $validator.errors does not show anything else. I would expect all the required fields from CompA…CompC to show up as well.
Am I validating something incorrectly or is validation skipping children component?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Optionally do not validate child components #719 - GitHub
Now when I am validating parent component it says it's invalid because of failing child rules. It would be nice to have an...
Read more >Unable to validate a child component from a parent component
I have a selectbox component. I want to reused it in other components.I'm able to reused the selectbox component in other components by ......
Read more >Child Component Validation - CodeSandbox
The Vue build version to load with the `import` command. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
Read more >Validation of child component | Blazor Forums - Syncfusion
Hi,. I have created the child component with the textbox, but the validation inside the component does not work. Some time ago you...
Read more >How to fire validation error for input field from child component ...
Create @api method to validate child components text input field. Here you can use template.queryselector to access the value of the text ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

v-ifremoves the elements from the DOM, vee-validate doesn’t validate any fields hidden byv-ifsince the directive won’t execute. You can usev-showif the form has multiple tabs has a similar structure. This will allow you to maintain the fields state until the form finally submits.If you are building something like a form with steps then it should work fine with
v-iforv-showregardless since each step would be required to be correct before proceeding, in that case. Persisting the validation state for each step is redundant.Thank you @logaretm