You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[x] Support request
[ ] Other... Please describe:
Current behavior
When upsert is used to replace firstForm FormGroup on 'example' key with a new secondForm FormGroup on 'example' key the store does not take the values from the new secondForm control it instead copies over the values from the old firstForm control into the secondForm control replacing the it's values.
firstForm = new FormGroup({
id: new FormControl("123")
});
secondForm = new FormGroup({
id: new FormControl("456")
});
this.manager.upsert("example", this.firstForm);
// this.manager.getControl("example").value = {"id":"123"}
this.manager.upsert("example", this.secondForm);
// this.manager.getControl("example").value = {"id":"123"} <--- old value
/** If the control already exist, patch the control with the store value */
Work around at the moment is to perform a clear on the 'example' key, removing the old form group so that when the new one is passed in it wont have an existing FormGroup at the 'example' key to copy data from.
this.manager.upsert("example", this.firstForm);
// this.manager.getControl("example").value = {"id":"123"}
this.manager.clear("example");
this.manager.upsert("example", this.secondForm);
// this.manager.getControl("example").value = {"id":"456"} <--- new value
Expected behavior
The secondForm values replace the store values.
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
It feels counterintuitive that an upsert method would change the values on the FormGroup being passed in to match the store. I'm aware this may in fact be me miss using this feature so any clarification would be appreciated.
I'm submitting a...
Current behavior
When upsert is used to replace firstForm FormGroup on 'example' key with a new secondForm FormGroup on 'example' key the store does not take the values from the new secondForm control it instead copies over the values from the old firstForm control into the secondForm control replacing the it's values.
Relevant section of the codebase
forms-manager/projects/ngneat/forms-manager/src/lib/forms-manager.ts
Line 547 in 0ee5eff
Work around at the moment is to perform a clear on the 'example' key, removing the old form group so that when the new one is passed in it wont have an existing FormGroup at the 'example' key to copy data from.
Expected behavior
The secondForm values replace the store values.
Minimal reproduction of the problem with instructions
https://stackblitz.com/edit/github-mt9mwh?file=src/app/example.component.ts
What is the motivation / use case for changing the behavior?
It feels counterintuitive that an upsert method would change the values on the FormGroup being passed in to match the store. I'm aware this may in fact be me miss using this feature so any clarification would be appreciated.
Environment
https://stackblitz.com/edit/github-mt9mwh?file=src/app/example.component.ts
Angular version: 9.1.13
Browser:
The text was updated successfully, but these errors were encountered: