-
Notifications
You must be signed in to change notification settings - Fork 27k
feat(forms): add support for pushing an array of controls to formarray #57102
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
Conversation
|
Is there anything I can do, add or expand upon to make this something we want to consider and/or merge? |
|
@MarkTechson As requested on youtube! Sorry to bother. |
Enables users to add an array of FormControls to a FormArray using its existing .push() method, instead of pushing each new FormControl one by one triggering events along the way.
9328c06 to
9757f20
Compare
|
As a curiosity, I ran a TGP which returned green. |
JeanMeche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
|
The internal failing tests seems to be a flake? Let me find out how to re-run |
kirjs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved-for: public-api
The code looks great, thank you for your contribution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
The code looks great, thank you for your contribution
|
This PR was merged into the repository by commit c353497. The changes were merged into the following branches: main |
|
Isn't this a breaking change if I have an array of arrays? |
Do you have a repro you can share @flensrocker? |
|
I can try to create one this evening (timezone CET). |
…formarray (angular#57102)" This reverts commit c353497.
FormArray isn't an array, so we should be good. If but curious if you can find a breaking usecase. |
|
I guess I was "overreacting", but my experience let me bring this up, because I also don't always think about corner cases. Yes, I can confirm that Now I'm thinking about, if it's possible to subclass an own I will investigate, but I don't think I find a breaking change. Thanks for listening! |
|
In case you come up with a case @flensrocker, let me know. I'll dive into Angular Forms API to see if they have a native way of detecting if it's a FormArray or a regular array and see if we can handle both situations as needed. But I think, considering the original API has been expanded from just accepting a TControl, the surface of changes for existing usage isn't that big. Or at least I would hope so! 😄 |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Enables users to add an array of FormControls to a FormArray using its existing .push() method, instead of pushing each new FormControl one by one triggering events along the way.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
FormArray.push()currently only accepts a singleFormControlorFormGroup, manipulating aFormArrayholding large datasets and using expensive validators is complicated by this behavior, as there is no easy way to refresh the dataset without breaking existing streams depending on its.valueChanges.Issue Number: N/A
What is the new behavior?
FormArray.push()now accepts both a singleFormControlorFormGroup, but also accepts an array of the same types. In case of an array, it will register all controls as expected and emit a single event after.Does this PR introduce a breaking change?
Other information
Ran into this issue myself working at a client, where we could not easily manipulate a
FormArraywhere we want to refresh a large dataset. Swapping it out for anew FormArray()seemed like the way, but this broke any existing streams subscribed to its original.valueChanges, making it difficult to keep everything in sync and reactive.This solution at least makes it possible to manipulate a dataset within a
FormArrayas a new dataset, instead of having to iterate over all new controls. A possible expansion on this solution, and to promote immutability, could be to offer an additional method that also internally clears the existing dataset so a full replace would be possible.Additionally, managed to run the entire test suite locally, except for
//packages/zone.js/test:karma_jasmine_test_ci_chromiumwhich seemed to not be able to connect to its ChromeHeadless browser and therefore fail. Hopefully the CI can run this test for me, but I'd still like to know what went wrong exactly. Short excerpt: