Skip to content
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
dankraw opened this issue Sep 9, 2014 · 7 comments

Comments

@dankraw
Copy link

dankraw commented Sep 9, 2014

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

@Narretz
Copy link
Contributor

Narretz commented Sep 10, 2014

This has been fixed since 1.3.0-rc.1

@Narretz Narretz closed this as completed Sep 10, 2014
@dankraw
Copy link
Author

dankraw commented Sep 10, 2014

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

@caitp
Copy link
Contributor

caitp commented Sep 10, 2014

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

@Narretz
Copy link
Contributor

Narretz commented Sep 10, 2014

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.

@Narretz Narretz reopened this Sep 10, 2014
@caitp
Copy link
Contributor

caitp commented Sep 10, 2014

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.

@Narretz
Copy link
Contributor

Narretz commented Sep 10, 2014

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.

@Narretz Narretz closed this as completed Sep 10, 2014
@dankraw
Copy link
Author

dankraw commented Sep 10, 2014

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants