diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 658bae6291..0a227a6bde 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -659,15 +659,14 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi } } - if (attrs.datepickerOptions) { - var options = scope.$parent.$eval(attrs.datepickerOptions); - if (options && options.initDate) { - scope.initDate = dateParser.fromTimezone(options.initDate, ngModelOptions.timezone); - datepickerEl.attr('init-date', 'initDate'); - delete options.initDate; - } - angular.forEach(options, function(value, option) { - datepickerEl.attr(cameltoDash(option), value); + if (scope.datepickerOptions) { + angular.forEach(scope.datepickerOptions, function(value, option) { + // Ignore this options, will be managed later + if (['minDate', 'maxDate', 'minMode', 'maxMode', 'initDate', 'datepickerMode'].indexOf(option) === -1) { + datepickerEl.attr(cameltoDash(option), value); + } else { + datepickerEl.attr(cameltoDash(option), 'datepickerOptions.' + option); + } }); } @@ -984,6 +983,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi require: ['ngModel', 'uibDatepickerPopup'], controller: 'UibDatepickerPopupController', scope: { + datepickerOptions: '=?', isOpen: '=?', currentText: '@', clearText: '@', diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index abf2b72100..55bde04502 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1849,6 +1849,110 @@ describe('datepicker', function() { expect(getTitle()).toBe('November 1980'); }); }); + + describe('min-date', function() { + it('should be able to specify a min-date through options', function() { + $rootScope.opts = { + minDate: new Date('September 12, 2010'), + shortcutPropagation: 'dog' + }; + + var wrapElement = $compile('
')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(index < 14); + }); + + $rootScope.opts.minDate = new Date('September 13, 2010'); + $rootScope.$digest(); + buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(index < 15); + }); + }); + }); + + describe('max-date', function() { + it('should be able to specify a max-date through options', function() { + $rootScope.opts = { + maxDate: new Date('September 25, 2010') + }; + + var wrapElement = $compile('')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(index > 27); + }); + + $rootScope.opts.maxDate = new Date('September 15, 2010'); + $rootScope.$digest(); + buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(index > 17); + }); + }); + }); + + describe('min-mode', function() { + it('should be able to specify min-mode through options', function() { + $rootScope.opts = { + minMode: 'month' + }; + + var wrapElement = $compile('')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + + expect(getTitle()).toBe('2010'); + }); + }); + + describe('max-mode', function() { + it('should be able to specify max-mode through options', function() { + $rootScope.opts = { + maxMode: 'month' + }; + + var wrapElement = $compile('')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + + expect(getTitle()).toBe('September 2010'); + clickTitleButton(); + assignElements(wrapElement); + expect(getTitle()).toBe('2010'); + clickTitleButton(); + assignElements(wrapElement); + expect(getTitle()).toBe('2010'); + }); + }); + + describe('datepicker-mode', function() { + beforeEach(inject(function() { + $rootScope.date = new Date('August 11, 2013'); + $rootScope.opts = { + datepickerMode: 'month' + }; + var wrapElement = $compile('')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + })); + + it('shows the correct title', function() { + expect(getTitle()).toBe('2013'); + }); + + it('updates binding', function() { + clickTitleButton(); + expect($rootScope.opts.datepickerMode).toBe('year'); + }); + }); }); describe('attribute `init-date`', function() {