Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ng-maxlength (or ng-minlength) attribute causes execution of input's ng-change expression #9001

Closed

Description

@dankraw

Hello,
I have stumbled upon an issue with ng-maxlength (same with ng-minlength) attribute of the text input (and textarea). After adding the validation and setting programmatically value of the input, the ng-change expression is being evaluated, while according to the docs, it should be executed only after user interaction.
I'm not 100% sure, but the issue occurs when the value being set for the input is valid.
Live example here: http://plnkr.co/edit/Fbbfm3vsYsAFmGVAL0Q8?p=preview

Activity

  1. added this to the 1.3.0-rc.2 milestone on Sep 10, 2014
  2. Narretz commented on Sep 10, 2014

    @Narretz
    Contributor

    This has been fixed since 1.3.0-rc.1

  3. dankraw commented on Sep 10, 2014

    @dankraw
    Author

    @Narretz Unfortunately, it's not fixed: http://plnkr.co/edit/7a1jEb2y2mdfODVeMmQv?p=preview
    I've changed the validator, so the input's value is now invalid. Same with ng-minlength.

  4. caitp commented on Sep 10, 2014

    @caitp
    Contributor

    I think this is actually correct, the documentation error is just that... a documentation error. It's the only sane way we can do it consistently for everything that uses ngModel --- I would consider this a non-bug

  5. Narretz commented on Sep 10, 2014

    @Narretz
    Contributor

    Ok, now it only happens when the validator returns false. Very inconsistent. I don't think this is right, as the model hasn't changed. Maybe ngChange never took inital scope values into account.

  6. caitp commented on Sep 10, 2014

    @caitp
    Contributor

    ngChange just registers a listener to ngModel's array of listeners which are notified when the model changes. It has no machinery for caring whether the value actually changed or not, that's ngModel's responsibility.

  7. Narretz commented on Sep 10, 2014

    @Narretz
    Contributor

    Ah, okay now I see it. ngChange fires because the model is set to undefined, because it's invalid. So it's working as intended. If you want invalid modelValues on $scope, you can use allowInvalid in ngModelOptions.

  8. dankraw commented on Sep 10, 2014

    @dankraw
    Author

    OK, so rc1 is fine as well as the docs. ;) Thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions