datepicker: allow dynamic mdMinDate and mdMaxDate
Actual Behavior:
What is the issue? *
mdMinDate and mdMaxDate do not allow the user to set different dates. Once the date is bound, the error will persist, even if the min or max date is changed. The calendar will display the proper range of valid dates. Once the value is changed, the error will be removed.
What is the expected behavior?
The error will disappear as soon as the min or max date value is changed to something valid.
CodePen (or steps to reproduce the issue): *
CodePen Demo which shows your issue:http://codepen.io/mckenzielong/pen/ggxLaQ
Angular Versions: *
Angular Version:1.5.9Angular Material Version:master
Additional Information:
Browser Type: *Opera / ChromeBrowser Version: *42 /55OS: *Windows 7 64 bitStack Traces:N/A
+1 This also happens when dynamically changing the model that is bound to the datepicker, it does not re-validate. For me, the only workaround was to use $timeout when updating the value.
Meant to share this ugly thing..
.directive('mdMinDate', MdMinMax('minDate'))
.directive('mdMaxDate', MdMinMax('maxDate'))
...
function MdMinMax(minOrMax) {
return () => {
return {
'required': ['?mdDatepicker'],
'link': (scope, elem, attrs, controller) => {
if (controller && controller[0]) {
scope.$watch((s) => controller[0][minOrMax], () => {
controller[0].updateErrorState();
});
}
}
};
};
}