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

Form not marked as dirty if new value is empty object #4678

Closed
2 of 5 tasks
hendrikheil opened this issue Feb 29, 2024 · 3 comments · Fixed by #4710
Closed
2 of 5 tasks

Form not marked as dirty if new value is empty object #4678

hendrikheil opened this issue Feb 29, 2024 · 3 comments · Fixed by #4710

Comments

@hendrikheil
Copy link

What happened?

Currently, if a value is changed to an empty object ({}), the isEqual util automatically assumes nothing has changed.

keys = Object.keys(a);
length = keys.length;

I think checking both objects and comparing their key counts would be a viable option to solving this without a noticable performance hit.

Reproduction steps

  1. Create any form with initial values:
const form = useForm({
  initialValues: {
    a: {
      exists: true,
    }
  }
});
  1. Empty the value of a
const [a] = form.defineField('a');
a.value = {};
  1. Inspect form.meta.dirty, this should be true, but it is false

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-issue-template-p3dgzu?file=src%2FApp.vue,src%2Fmain.ts

Code of Conduct

@evpaassen
Copy link
Contributor

The isssue is not limited to empty objects. Actually, every single attribute combination may be missing without the form being marked as dirty. Take this example:
https://stackblitz.com/edit/vee-validate-issue-template-i9yukh?file=src%2FApp.vue

The problem is indeed in the isEqual function in utils/assertions.ts. Since the change in 32537e1 (#4341), this method is not commutative anymore and I think that is a bug. This is demonstrated here:
https://stackblitz.com/edit/vee-validate-issue-template-bsm92l?file=src%2FApp.vue

Maybe I can try to come up with a PR to fix it.

evpaassen added a commit to evpaassen/vee-validate that referenced this issue Mar 22, 2024
evpaassen added a commit to evpaassen/vee-validate that referenced this issue Mar 22, 2024
@evpaassen
Copy link
Contributor

Did anyone have the chance to look at this issue yet? I submitted a PR (#4710) half a year ago, but I haven't heard anything yet.

@logaretm
Copy link
Owner

@evpaassen Checked your PR, sorry for the delay. I tested it and merged it just now.

This will go out in the next patch, thank you all for reporting and fixing this.

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

Successfully merging a pull request may close this issue.

3 participants