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

[v4] bug when removing items from array fields #3325

Closed
bdreesen opened this issue May 28, 2021 · 2 comments
Closed

[v4] bug when removing items from array fields #3325

bdreesen opened this issue May 28, 2021 · 2 comments
Labels
🐛 bug Unintended behavior

Comments

@bdreesen
Copy link

Versions

  • vee-validate: 4.1.18 - 4.4.1
  • vue: 3.0.x

Describe the bug

Working with array fields, when you remove an item that isn't the last one, the next item is duplicated in the form values.
This is a result from a change introduced in #3166

To reproduce

Steps to reproduce the behavior:

  1. Go to demo link
  2. Add 3 users
  3. Remove the middle one
  4. Click submit
  5. Form values still contains 3 users and one of those is a duplicate

Expected behavior

Form values should only contain 2 users.

Demo link

Codesandbox

@logaretm logaretm added the 🐛 bug Unintended behavior label May 28, 2021
@apeling
Copy link

apeling commented May 28, 2021

I have been banging my head against array fields for nearly a week (particularly working with preloaded values, reactive schema, and form resets). Trying to work up a CodeSandbox to get some discussion going on the correct way to work with array fields. Right now I have ton of hacky code to trying to deal with the tug of war between the model and the array driving the count of entries.

@logaretm
Copy link
Owner

Thank you for reporting this, indeed it was related to #3166 because when the fields didn't unset the stale path it would duplicate the values in the case of array fields.

I have implemented a fix for it by cleaning up the old value when the remaining field exchanges its name.

Will tag a patch for this shortly.

@apeling Feel free to create a discussion where you can describe your use case and the difficulties with this and I will try to make it better/easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants