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 not re-running when Array items modified directly #3926

Closed
2 of 5 tasks
darushton opened this issue Sep 13, 2022 · 1 comment · Fixed by #3929
Closed
2 of 5 tasks

Validation not re-running when Array items modified directly #3926

darushton opened this issue Sep 13, 2022 · 1 comment · Fixed by #3929
Labels
🐛 bug Unintended behavior 🛳 In PR This issue is being addressed in a PR

Comments

@darushton
Copy link

darushton commented Sep 13, 2022

What happened?

Having upgraded vee-validate recently, we're seeing an issue in one of our apps around array validation.

When we have an array with a validated shape, if we modify the items directly, validation does not appear to be re-run (initial validation errors are not removed and new validation errors are not generated).

This did work prior to 4.6.0 specifically.

Post 4.6.0, the only thing that seems to trigger validation is creating a new array with copies of the initial items.

I've created a simplified example here:

https://stackblitz.com/edit/vee-validate-v4-array-fields-6fe98t?file=src/App.vue

You'll see that:

  • Initially the first user in the list has no name, so a validation error shows
  • Clicking 'Clear' next to 'Susan' clears their name, but no validation error shows

If you update package.json to use vee-validate 4.5.11, and then refresh and repeat the above steps, the validation error is shown when clearing 'Susan'.

Is this a bug or have we been relying on something working that shouldn't have previously?

We've resolved in our app by rolling vee-validate back to an earlier version, but have you got any suggestions for a long term solution for us?

Many thanks!

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://stackblitz.com/edit/vee-validate-v4-array-fields-6fe98t?file=src/App.vue

Code of Conduct

@logaretm
Copy link
Owner

logaretm commented Sep 17, 2022

Perhaps this is related to this fix which was introduced in 4.6.

Basically mutating the object like that causes the watcher to see both old and new values as the same one. I will see if a workaround can be implemented. Replacing the entire value works better because they no longer share the same reference.

I will try to see if that's indeed the issue or not.

@logaretm logaretm added the 🐛 bug Unintended behavior label Sep 17, 2022
@logaretm logaretm added the 🛳 In PR This issue is being addressed in a PR label Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unintended behavior 🛳 In PR This issue is being addressed in a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants