Skip to content

Regression caused by the min/max validators in 4.2.0 #17491

Description

@rusev

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

  1. tytskyi commented on Jun 14, 2017

    @tytskyi

    Good example on why some features should not be bundled into the core but go as a separate package.

  2. trotyl commented on Jun 14, 2017

    @trotyl
    Contributor

    Seems that every new directive/pipe would be a regression then.

  3. kemsky commented on Jun 14, 2017

    @kemsky

    Generic problem, we can not override directives at all. Imagine you are happily using forms module, but want to override required validator - you can not... One way is to create your own my-required or something. Angular could change selectors to use :not([NgDisableRequired]), but it is not elegant either.

  4. tytskyi commented on Jun 14, 2017

    @tytskyi

    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/max directives 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/contrib with ValidatorRequiredModule).

    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:

  5. added
    regression
    on Jun 15, 2017
  6. kara commented on Jun 16, 2017

    @kara
    Contributor

    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.

  7. added a commit that references this issue on Jun 16, 2017
    1fc6f5d
  8. added 3 commits that reference this issue on Jun 16, 2017
    232bd93
    b8c39cd
  9. 6 remaining items

  10. added 2 commits that reference this issue on Aug 28, 2017
    a27794b
    ee29900
  11. henev commented on Oct 22, 2017

    @henev

    Will min/max be introduced into the upcoming major version 5 or should we wait for the 6?

  12. danwulff commented on Nov 17, 2017

    @danwulff

    @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.

  13. Toxicable commented on Nov 17, 2017

    @Toxicable

    @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.

  14. JaapMosselman commented on Dec 12, 2017

    @JaapMosselman

    But the Angular Upgrade Guide is mentioning this for migrating from 4.4 to 5.0:

    If you created a custom form control with min and max input properties, you will need to adapt to the new behavior by renaming them or using the native validators

    Seems to be wrong?

  15. IgorMinar commented on Dec 12, 2017

    @IgorMinar
    Contributor

    @StephenFluin can you please update the guide?

  16. cexbrayat commented on Dec 12, 2017

    @cexbrayat
    Member

    @IgorMinar the plan is to reintroduce the directives in a future major update?

  17. Maximaximum commented on Dec 13, 2017

    @Maximaximum

    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? :)

  18. Maximaximum commented on Dec 13, 2017

    @Maximaximum

    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]

  19. Maximaximum commented on Dec 19, 2017

    @Maximaximum

    Actually, it can be even more specific like: input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel] :)

  20. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    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.

  21. locked and limited conversation to collaborators on Sep 13, 2019
  22. added 2 commits that reference this issue on Nov 20, 2026
    ce2b348
    01003b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: formsregressiontype: bug/fix

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions