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

Default value is not cloned deeply as the original object type #268

Closed
anschm opened this issue Jul 22, 2022 · 4 comments
Closed

Default value is not cloned deeply as the original object type #268

anschm opened this issue Jul 22, 2022 · 4 comments
Labels

Comments

@anschm
Copy link
Contributor

anschm commented Jul 22, 2022

The default value is not cloned deeply as the original type e.g. Date or any other object. The copy is made by the following code:

const defaultValues: FormInterface = deepCopy(formGroup.value);

and the deepCopy method is implemented like:

export const deepCopy = (value: T): T => JSON.parse(JSON.stringify(value));

This is not a deepy copy of an object. The object is transformed to an string or JSON. If the form value type is a Date and you pass a new Date() as default value the inner value is a string. Thats not correct. In this case the moste date pickers handles the inner value as a Date object.

We should use deepCopy from lodash or any other library which makes a deep object copy.

@maxime1992
Copy link
Collaborator

Sounds fair enough. I think I'd like to default to the current implementation and let people pass a custom deepCopy function to avoid having another dependency but it feels legit for now and I think we could accept a PR where deepCopy is replaced by one coming from lodash (please use lodash-es though).

Feel free to raise a PR

@anschm
Copy link
Contributor Author

anschm commented Jul 26, 2022

I would, but your project and my fork have different changes because of all other pull requests I created and which are not merged. I fixed this issues on my fork on this branch:
https://github.com/dillybeeze/ngx-sub-form/tree/fix/deep_clone_default_value

If you have any idea how to get only the 3 changes without making a new fork, feel free to tell me.

@anschm
Copy link
Contributor Author

anschm commented Jul 27, 2022

PR is available #270

anschm added a commit to dillybeeze/ngx-sub-form that referenced this issue Aug 2, 2022
@github-actions
Copy link

github-actions bot commented Aug 2, 2022

🎉 This issue has been resolved in version 6.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants