diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js
index 143955926e..d4a133beb6 100644
--- a/src/datepicker/datepicker.js
+++ b/src/datepicker/datepicker.js
@@ -94,23 +94,21 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
break;
case 'maxDate':
case 'minDate':
- if ($scope.datepickerOptions[key]) {
- $scope.$watch('datepickerOptions.' + key, function(value) {
- if (value) {
- if (angular.isDate(value)) {
- self[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone);
- } else {
- self[key] = new Date(dateFilter(value, 'medium'));
- }
+ $scope.$watch('datepickerOptions.' + key, function(value) {
+ if (value) {
+ if (angular.isDate(value)) {
+ self[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone);
} else {
- self[key] = null;
+ self[key] = new Date(dateFilter(value, 'medium'));
}
+ } else {
+ self[key] = datepickerConfig[key] ?
+ dateParser.fromTimezone(new Date(datepickerConfig[key]), ngModelOptions.timezone) :
+ null;
+ }
- self.refreshView();
- });
- } else {
- self[key] = datepickerConfig[key] ? dateParser.fromTimezone(new Date(datepickerConfig[key]), ngModelOptions.timezone) : null;
- }
+ self.refreshView();
+ });
break;
case 'maxMode':
diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js
index 87c605e4da..cbfa53a937 100644
--- a/src/datepicker/test/datepicker.spec.js
+++ b/src/datepicker/test/datepicker.spec.js
@@ -920,6 +920,30 @@ describe('datepicker', function() {
});
});
+ describe('minDate with no initial value', function() {
+ beforeEach(function() {
+ $rootScope.options = {};
+ $rootScope.date = new Date('September 10, 2010');
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
+ });
+
+ it('should toggle appropriately', function() {
+ var buttons = getAllOptionsEl();
+ angular.forEach(buttons, function(button, index) {
+ expect(angular.element(button).prop('disabled')).toBe(false);
+ });
+
+ $rootScope.options.minDate = new Date('September 12, 2010');
+ $rootScope.$digest();
+
+ refreshedButtons = getAllOptionsEl();
+ angular.forEach(refreshedButtons, function(button, index) {
+ expect(angular.element(button).prop('disabled')).toBe(index < 14);
+ });
+ });
+ });
+
describe('minDate', function() {
beforeEach(function() {
$rootScope.options = {
@@ -1019,6 +1043,30 @@ describe('datepicker', function() {
});
});
+ describe('maxDate with no initial value', function() {
+ beforeEach(function() {
+ $rootScope.options = {};
+ $rootScope.date = new Date('September 10, 2010');
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
+ });
+
+ it('should toggle appropriately', function() {
+ var buttons = getAllOptionsEl();
+ angular.forEach(buttons, function(button, index) {
+ expect(angular.element(button).prop('disabled')).toBe(false);
+ });
+
+ $rootScope.options.maxDate = new Date('September 25, 2010');
+ $rootScope.$digest();
+
+ refreshedButtons = getAllOptionsEl();
+ angular.forEach(refreshedButtons, function(button, index) {
+ expect(angular.element(button).prop('disabled')).toBe(index > 27);
+ });
+ });
+ });
+
describe('maxDate', function() {
beforeEach(function() {
$rootScope.options = {