FormGroup upsert takes value of previous FormGroup
field123 opened this issue · 0 comments
I'm submitting a...
[ ] 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
Relevant section of the codebase
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
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:
- Chrome (desktop) version XX
- Chrome (Android) version XX
- Chrome (iOS) version XX
- Firefox version XX
- Safari (desktop) version XX
- Safari (iOS) version XX
- IE version XX
- Edge version XX