material icon indicating copy to clipboard operation
material copied to clipboard

datepicker: allow dynamic mdMinDate and mdMaxDate

Open mckenzielong opened this issue 9 years ago • 2 comments

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.9
  • Angular Material Version: master

Additional Information:

  • Browser Type: * Opera / Chrome
  • Browser Version: * 42 /55
  • OS: * Windows 7 64 bit
  • Stack Traces: N/A

mckenzielong avatar Jan 25 '17 00:01 mckenzielong

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

jobo26 avatar Jan 26 '17 11:01 jobo26

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();
          });
        }
      }
    };
  };
}

mckenzielong avatar Mar 06 '17 20:03 mckenzielong