From d2bf5a92c1391c4ef21f557086dec43776102659 Mon Sep 17 00:00:00 2001 From: selema Date: Thu, 24 May 2018 12:53:57 +0300 Subject: [PATCH] add watchers for min/max date to set correct validity state of input --- js/angular-material-datetimepicker.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/angular-material-datetimepicker.js b/js/angular-material-datetimepicker.js index 4f6d134..99fdd05 100644 --- a/js/angular-material-datetimepicker.js +++ b/js/angular-material-datetimepicker.js @@ -200,6 +200,26 @@ if (ngModel.$options.timezone) offset = ngModel.$options.timezone; } if (offset==='utc' || offset==='UTC') offset = 0; + + if (scope.minDate) { + scope.$watch(function () { + return scope.minDate; + }, function (val2, val1) { + if (val2 !== val1) { + ngModel.$setValidity('min', !scope.currentDate.isBefore(scope.minDate)); + } + }); + } + + if (scope.maxDate) { + scope.$watch(function () { + return scope.maxDate; + }, function (val2, val1) { + if (val2 !== val1) { + ngModel.$setValidity('max', !scope.currentDate.isAfter(scope.maxDate)); + } + }); + } ngModel.$formatters.push(function (value) { if (typeof value === 'undefined') return;