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

max or min causes input type=date to fire $viewChangeListeners during every validation #10125

Closed
mdvorak opened this issue Nov 19, 2014 · 3 comments

Comments

@mdvorak
Copy link

mdvorak commented Nov 19, 2014

Angular 1.3.3
Problem is that in general, objects are compared using !==, which does not work as expected for Date objects. Culprit is this function

function writeToModelIfNeeded() {
  if (ctrl.$modelValue !== prevModelValue) {
    ctrl.$$writeModelToScope();
  }
}

for this to work, it would have to be same instance of the Date. For date input types, this comparsion should be smarter and compare Date.getTime() insted.
This also causes to fire changed event during initialization when max or min are used (since they call $validate).

Sample: http://plnkr.co/edit/vXNfLHkF9wbhjJRueblL?p=preview

In the sample, you can check that in writeToModelIfNeeded during init are both prevModelValue and $modelValue same, just not the same instance.

@mdvorak
Copy link
Author

mdvorak commented Nov 19, 2014

This may be related to #9913, but I did not test it.

@Narretz
Copy link
Contributor

Narretz commented Nov 19, 2014

It is indeed the same issue. It will be fixed in 1.3.4, you can see a preview here: http://plnkr.co/edit/YpCpE1NQM83sXo8vY18d?p=preview

@mdvorak
Copy link
Author

mdvorak commented Nov 20, 2014

Ah, thats great news, next time I'll test against master as well :) Thanks

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

2 participants