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

FormGroup upsert takes value of previous FormGroup #26

Open
8 tasks done
field123 opened this issue Apr 8, 2021 · 0 comments
Open
8 tasks done

FormGroup upsert takes value of previous FormGroup #26

field123 opened this issue Apr 8, 2021 · 0 comments

Comments

@field123
Copy link

field123 commented Apr 8, 2021

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

/** 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant