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

Open
2 of 5 tasks
hendrikheil opened this issue Feb 29, 2024 · 1 comment · May be fixed by #4710
Open
2 of 5 tasks

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

hendrikheil opened this issue Feb 29, 2024 · 1 comment · May be 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

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 evpaassen linked a pull request Mar 22, 2024 that will close this issue
evpaassen added a commit to evpaassen/vee-validate that referenced this issue Mar 22, 2024
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.

2 participants