Repository navigation
Description
I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request
Current behavior
Version 4.2.0 introduces min and max validators.
The issue arises when a custom component has min | max input property and that component implements ControlValueAccessor and is registered as a validator (custom validation logic requirements).
When the user wraps that component in a FormGroup the default min|max validators are always triggered and there is no way of instructing them that my component min, max properties are not meant to be validated.
This behavior will be also true if a custom component (which implements ControlValueAccessor) has input property that matches any of the built-in validator directives. For example if my custom component has input properties such as: min, max, minlength, maxlength etc.
Expected behavior
There should be a way to suppress Angular validator directives for such properties if required by the component author.
Minimal reproduction of the problem with instructions
Prior version 4.2.0 - http://plnkr.co/edit/QDoXhau2e1SuAuJ7tOwk?p=preview - no validation errors
With version 4.2.0 - http://plnkr.co/edit/gqtdQqL7DlY0UC1H6M0R?p=preview - validation errors
What is the motivation / use case for changing the behavior?
There should be mechanism for preventing Angular validator directives for input properties that matches built-in validation directives. These input properties might have a bit different meaning in the component context.
- Angular version: 4.2.0
Activity
tytskyi commentedon Jun 14, 2017
Good example on why some features should not be bundled into the core but go as a separate package.
trotyl commentedon Jun 14, 2017
Seems that every new
directive/pipewould be a regression then.kemsky commentedon Jun 14, 2017
Generic problem, we can not override directives at all. Imagine you are happily using forms module, but want to override
requiredvalidator - you can not... One way is to create your ownmy-requiredor something. Angular could change selectors to use:not([NgDisableRequired]), but it is not elegant either.tytskyi commentedon Jun 14, 2017
Yep, additional attributes for turning off behaviour looks not friendly and will escalate the mess quickly.
As the current solution i propose to remove exports for
min/maxdirectives ASAP and any mentions in the docs. While not too late. But hold their code and then export them within new solution for directives scoping. (I understand it is a bit radical)My further proposal is to separate things that are not essential out of core, OR at least out of Forms Module.
And scope each directive under named module, like
ValidatorRequiredModule(alternatively under npm package@angular/contribwithValidatorRequiredModule).Since only NgModule is true scope for the directives. This will unlock to "override" logic of directives that match names of standard html attributes and generally be more flexible with directives that are shipped with angular itself.
The downside of this would be frustration from existing users (I used to import only FormsModule, now i need to import 3 modules in order to use standard browser functionality!!! RAGE RAGE RAGE etc!)
Related issues that suffer from limitation of overriding directives:
Validator.email may need some rework - Or a new universal email validator is required #17296 - email validator - something that developers expect regardless of conforming to html5 spec
Feature Request: Add a delay option to routerLink #17485 - feat. request for adding delay timeout
routerLink- doesn't look like good addition to the core, but would be cool to use different directive under the same namekara commentedon Jun 16, 2017
For now, we are going to remove the exports for the min/max validator directives, as their addition is a breaking change. At the least, we should wait to add them until a major version. In the meantime, we will have further discussion about what the best solution is going forward for all validator directives.
fix(forms): temp roll back breaking change with min/max directives
fix(forms): temp roll back breaking change with min/max directives
fix(forms): temp roll back breaking change with min/max directives
6 remaining items
fix(forms): temp roll back breaking change with min/max directives
fix(forms): roll back breaking change with min/max directives
henev commentedon Oct 22, 2017
Will min/max be introduced into the upcoming major version 5 or should we wait for the 6?
danwulff commentedon Nov 17, 2017
@IgorMinar @kara Why are these not available in 5.0? (I'm currently using 5.0.2)
I was expecting min / max directives to be available as validators (template forms) after 4.x. Are they supposed to be available? Should I open a new issue? Thanks.
Toxicable commentedon Nov 17, 2017
@danwulff it was never said they would be available for v5
They are and have been available to ReactiveForms but if the directives were re-implemented as they were before they'd cause a regression again, they need to be renamed or a another strategy needs to be thought of before doing this.
JaapMosselman commentedon Dec 12, 2017
But the Angular Upgrade Guide is mentioning this for migrating from 4.4 to 5.0:
Seems to be wrong?
IgorMinar commentedon Dec 12, 2017
@StephenFluin can you please update the guide?
cexbrayat commentedon Dec 12, 2017
@IgorMinar the plan is to reintroduce the directives in a future major update?
Maximaximum commentedon Dec 13, 2017
So, we're now having angular 5.1.0, but the min and max validator directives are still not available. Is there going to be a fix for this one day? :)
Maximaximum commentedon Dec 13, 2017
BTW, a possible solution for this issue might be to use this selector instead, so that the directives work solely for an
<input>:input[min][formControlName],input[min][formControl],input[min][ngModel]Maximaximum commentedon Dec 19, 2017
Actually, it can be even more specific like:
input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]:)angular-automatic-lock-bot commentedon Sep 13, 2019
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.
fix(forms): temp roll back breaking change with min/max directives
fix(forms): roll back breaking change with min/max directives