Versions
Describe the bug
I am using vee-validate on a multi-step form. I have an outer ValidationObserver and multiple inner ValidationObserver for the steps. If I proceed from step 1 to step 2, the fields in the step 2 are validated immediately - showing the error messages without having touched the inputs.
To reproduce
Steps to reproduce the behavior:
<ValidationObserver v-slot="{ handleSubmit, errors }" tag="div"><ValidationObserver
v-if="step === 0"
tag="div"
>
<ValidationProvider
name="name"
tag="div"
rules="required"
>
onSubmit (e) {
if (this.step >= 2) {
console.log('do something')
}
this.step++
}
Expected behavior
No validation on step changes.
Demo link
Also happens in the docs samples for nested-observers. Click 'Next' and the firstName field error message shows up.
Desktop (please complete the following information):
This isn't really down to Vee-Validate itself, but Vue. Vue attempts to keep a similar DOM structure and patch any changes manually, instead of constantly rendering new elements all the time.
https://www.telerik.com/blogs/in-vue-when-do-i-actually-need-the-key-attribute-and-why
All you need to do here is add a key attribute, with a unique key for the observer.
@DM2489
oh my ... 馃檲
I mistakenly called a validation reset first on every step change but I actually added a transition and that needs keys anyway, so it works like a charm (without the reset). 馃榾
sorry, my fault. cheers for the hint though. 馃憤
Most helpful comment
This isn't really down to Vee-Validate itself, but Vue. Vue attempts to keep a similar DOM structure and patch any changes manually, instead of constantly rendering new elements all the time.
https://www.telerik.com/blogs/in-vue-when-do-i-actually-need-the-key-attribute-and-why
All you need to do here is add a
keyattribute, with a unique key for the observer.https://codesandbox.io/s/codesandbox-1b13t