feat(forms): support type set in form validators
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
- [ ] Bugfix
- [x] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Documentation content changes
- [ ] angular.io application / infrastructure changes
- [ ] Other... Please describe:
What is the current behavior?
Currently, using Validators.required, Validators.minLength and Validators.maxLength validators don't work with sets because a set has a size property instead of a length property.
What is the new behavior?
Validators.required, Validators.minLength and Validators.maxLength validators are working with sets.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
I assume this is for custom controls that give a Set when calling .value?
I assume this is for custom controls that give a
Setwhen calling.value?
yes exactely, eg. const control = new FormControl(new Set(), [Validators.required]).
We often use this in context of a chip input to easy avoid duplicates.
I don't think this is traditionally a use case we have thought much about, WDYT @AndrewKushnir?
Thank you for contributing @jeripeierSBB, but we are going to put this on the back burner for now. We currently do not support Set or Map anywhere, and if we decide to do so, we probably want to update every API at once.
Can you open a Feature Request instead (e.g. "Forms should accept Set collections in addition to arrays")? Thanks!
@dylhunn Thank you for your statement, I will open a feature request. Just for my understanding, can you give me a hint, where at other places in forms as validators the type does matter? Or in other words, where would additional changes be required? Thanks!
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
As discussed in #46101, there is significant community interest in this feature. I will review this PR this week.
2023 edit: oops. Time flies, I'll try to have a look