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

setValues doesn't respect non plain objects #4287

Closed
5 tasks done
VladStepanov opened this issue May 23, 2023 · 0 comments · Fixed by #4289
Closed
5 tasks done

setValues doesn't respect non plain objects #4287

VladStepanov opened this issue May 23, 2023 · 0 comments · Fixed by #4289
Labels
🐛 bug Unintended behavior

Comments

@VladStepanov
Copy link
Contributor

VladStepanov commented May 23, 2023

What happened?

I have a case where i have to store instance of File in my form.
But when i call setValues({ file: new File() }), i get a { file: {} }, instead of { file: File }

I've found an issue in function merge

export function merge(target: any, source: any) {
Object.keys(source).forEach(key => {
if (isObject(source[key])) {
if (!target[key]) {
target[key] = {};
}
merge(target[key], source[key]);
return;
}
target[key] = source[key];
});
return target;
}

There should be 1 more guard for isPlainObject(near isObject guard). Here is lodash implementation
https://github.com/lodash/lodash/blob/master/isPlainObject.js

Reproduction steps

  1. Create a form(via useForm) with initial form object like: { file: null }
  2. Try to setValues to form with non-plain object, for example instance of new File()
  3. console.log values object, instead of { file: File } we will found { file: {} }

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/nuxt-starter-addc1i?file=app.vue

Code of Conduct

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