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] resetField does not update dirty flag when setting value #3272

Closed
v1r0x opened this issue Apr 21, 2021 · 2 comments · Fixed by #3274
Closed

[v4] resetField does not update dirty flag when setting value #3272

v1r0x opened this issue Apr 21, 2021 · 2 comments · Fixed by #3274
Labels
🐛 bug Unintended behavior

Comments

@v1r0x
Copy link

v1r0x commented Apr 21, 2021

Versions

  • vee-validate: 4.3.0
  • vue: 3.0.11

Describe the bug

When using resetField() and setting value to anything different than the initial value, the dirty flag is not updated

const {
    resetField,
    meta,
} = useField('name', yup.string(), {
    initialValue: 'Value'
});
// Make changes to field 'name'
resetField({
    value: 'New Value'
});
// check value of meta.dirty (should be false, but is true)

This sets the input's value to New Value, but the input is still dirty.
But when using this code:

const {
    resetField,
    meta,
} = useField('name', yup.string(), {
    initialValue: 'Value'
});
// Make changes to field 'name'
resetField({
    value: 'Value'
});
// check value of meta.dirty (should be false, and is false)

Then the input's value is set back to Value and dirty flag is set to false

To reproduce

Steps to reproduce the behavior:

  1. Attach resetField() method to input field using useField() and set an initialValue
  2. Modify content of the input field
  3. Trigger resetField() with a value different from initialValue from step 1 resetField({value: 'New Value'})
  4. dirty flag in meta is not updated (still true)

Expected behavior
As I understand the resetField() method, it should reset the field's state (at least dirty flag IMO).

Did I misunderstand how resetField() should work or is this a bug?
If I use resetField() in a wrong way: Is there a solution to set a new value and reset the dirty flag?
Thank you!

@logaretm
Copy link
Owner

This seems like a bug, will check it out tonight

@v1r0x
Copy link
Author

v1r0x commented Apr 22, 2021

Thank you for your quick response and fix!
You rock 🤘 🎉

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

Successfully merging a pull request may close this issue.

2 participants