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

FormArray helpers to remove controls. #40

Closed
MarioArnt opened this issue Aug 14, 2020 · 3 comments
Closed

FormArray helpers to remove controls. #40

MarioArnt opened this issue Aug 14, 2020 · 3 comments

Comments

@MarioArnt
Copy link
Contributor

MarioArnt commented Aug 14, 2020

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Hello,

I'm using the lib and it would be great if there was more methods to remove controls from FormArray

Currently there's only a removeAt(index: number) method (inherited from @angular/forms) which is not very convenient to remove a control by value or by a given predicate.

I am thinking about something like this in the FormArray class:

removeWhen(predicate: (value: T) => boolean) {
  for (let i = 0; i < this.length; ++i) {
    if (predicate(this.at(i).value)) {
      this.removeAt(i);
    }
  }
};

remove(value: T) {
  this.removeWhen((v) => v === value);
};

I can make a PR if you are interested by such a feature 🚀

Thanks for your work 👍

BTW, the link to the repo is outdated on NPM, you should update repo field

@NetanelBasal
Copy link
Member

Sounds good. We just need to think about a better name. You can submit a PR.

@danzrou
Copy link
Collaborator

danzrou commented Aug 14, 2020

I suggest providing the whole control in the predicate as we might want to consider disabled or other control states too

@MarioArnt
Copy link
Contributor Author

@NetanelBasal I created PR #41 for this, feel free to suggest other names for the new methods

Good point @danzrou ! I provided the whole control so it is possible to use any property (disable, dirty, status etc...) in the predicate

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

3 participants