Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation with v-if on native html form #3415

Closed
1 of 5 tasks
vencakrecl opened this issue Jul 27, 2021 · 2 comments
Closed
1 of 5 tasks

Validation with v-if on native html form #3415

vencakrecl opened this issue Jul 27, 2021 · 2 comments
Labels
🐛 bug Unintended behavior wontfix This issue won't be fixed due to some outside powers

Comments

@vencakrecl
Copy link

vencakrecl commented Jul 27, 2021

What happened?

When the form is displayed for first time then run validation and ends with errors. For second time is displayed form is valid. When I use Form component everything is ok. See https://codesandbox.io/s/custom-text-input-with-vee-validate-v4-forked-elbwt?file=/src/App.vue

Reproduction steps

No response

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

No response

Demo link

https://codesandbox.io/s/custom-text-input-with-vee-validate-v4-forked-elbwt?file=/src/App.vue

Code of Conduct

@vencakrecl vencakrecl changed the title Validation v-if block Validation with v-if on native html form Jul 27, 2021
@logaretm logaretm added the 🐛 bug Unintended behavior label Jul 29, 2021
@logaretm
Copy link
Owner

Thank you for reporting this, this is indeed a weird inconsistency between the two variants. Will mark it as a bug and will check it out when I can.

@logaretm
Copy link
Owner

logaretm commented Aug 5, 2021

Took another look at this, this is caused by the fix for #3342

To explain this better, basically vee-validate has already validated the form when you called useForm in your setup function. When the inputs are mounted they just inherit their previous errors.

I don't think it is possible to cater for both use-cases, as vee-validate isn't in a good position to determine if inputs should inherit their previous errors or not.

This makes me more inclined to have error messages rendered at all times and give the user control over when to show them (with touched or dirty). But the problem here is this is a huge breaking change and won't be introduced in 4.x

As a workaround for your case, you could call resetForm when the visibility changes or make sure you show your errors if the field is touched which you can access in meta.touched.

@logaretm logaretm closed this as completed Aug 5, 2021
@logaretm logaretm added the wontfix This issue won't be fixed due to some outside powers label Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unintended behavior wontfix This issue won't be fixed due to some outside powers
Projects
None yet
Development

No branches or pull requests

2 participants