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

datepicker: does not reset $modelValue to null when invalid - this means ng-change doesn't fire either #10231

Closed
johnjesse opened this issue Jan 6, 2017 · 2 comments
Assignees
Labels
resolution: too risky There is too much risk or disruption with this proposal for our limited resources.

Comments

@johnjesse
Copy link

Actual Behavior:

  • What is the issue? *

the datepicker does not reset the $modelValue to null when the input is invalid. I think this is because it uses $setValidity instead of registering validators. Importantly this is opposite to how angular normally behaves.

As it doesn't reset the model value then ng-change events don't fire, normally they do fire when you move form a valid to an invalid modelValue.

  • What is the expected behavior?

The $modelValue should be set to null

CodePen (or steps to reproduce the issue): *

  • CodePen Demo which shows your issue:

http://codepen.io/anon/pen/OWVbNP

  • Details:

enter a valid date e.g. 1/1/1 - the model value updates accordingly
change date to invalid e.g. 2001/20001/20001 - the model value stays the same as it was before

compare this to the input box

enter a valid number e.g. 1 - the model value is 1
change to an invalid number e.g. -1 - the model value is reset to null

Angular Versions: *

  • Angular Version:1.5.8
  • Angular Material Version:1.1.1

Additional Information:

  • Browser Type: * Chrome
  • Browser Version: *
  • OS: * Windows
  • Stack Traces:

Shortcut to create a new CodePen Demo.
Note: * indicates required information. Without this information, your issue may be auto-closed.

Do not modify the titles or questions. Simply add your responses to the ends of the questions.
Add more lines if needed.

@johnjesse
Copy link
Author

Actually, looking at this angular/angular.js#8357 this isn't really a bug.

But it is an issue when building composite custom form controls - e.g. a date-time editor - ng-change allows a nice way to update a composite control's ng-model from one of it's constituents. Otherwise you'd need to set up a series of watches that do the error checking etc..

any chance that your going to move from $setvalidity, to using the $validators pipeline any time soon?

@Splaktar Splaktar changed the title datepicker does not reset $modelValue to null when invalid - this means ng-change doesn't fire either datepicker: does not reset $modelValue to null when invalid - this means ng-change doesn't fire either May 27, 2020
@Splaktar Splaktar self-assigned this May 27, 2020
@Splaktar Splaktar added the resolution: too risky There is too much risk or disruption with this proposal for our limited resources. label May 27, 2020
@Splaktar
Copy link
Contributor

Splaktar commented May 27, 2020

Thank you for this report and your analysis. I'm still seeing this in 1.1.22.

As you stated, it seems like it would be better to use the $validators pipeline. However, at this time this could be a risky change that could introduce some unwanted breaking changes.

I'm going to close this, but if you still feel strongly about it, I would certainly be open to reviewing and possibly merging a PR that converted the datepicker and calendar to the $validators pipeline in 1.2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolution: too risky There is too much risk or disruption with this proposal for our limited resources.
Projects
None yet
Development

No branches or pull requests

2 participants