Skip to content

Commit a10a2d4

Browse files
Alex AlbinoAlex Albino
Alex Albino
authored and
Alex Albino
committed
fix(datepicker): Manually appliying angular-ui#1913 to 0\.11 release
1 parent 42cc3f2 commit a10a2d4

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/datepicker/datepicker.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
8181
if ( this.element ) {
8282
this._refreshView();
8383

84-
var date = ngModelCtrl.$modelValue ? new Date(ngModelCtrl.$modelValue) : null;
85-
ngModelCtrl.$setValidity('date-disabled', !date || (this.element && !this.isDisabled(date)));
84+
if (ngModelCtrl.$modelValue) {
85+
var date = ngModelCtrl.$modelValue ? new Date(ngModelCtrl.$modelValue) : null;
86+
ngModelCtrl.$setValidity('date-disabled', !date || (this.element && !this.isDisabled(date)));
87+
}
8688
}
8789
};
8890

src/datepicker/test/datepicker.spec.js

+33
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,40 @@ describe('datepicker directive', function () {
693693
});
694694

695695
});
696+
697+
describe('attribute `ng-model`', function() {
698+
var dateFilter, today;
699+
beforeEach(inject(function(_dateFilter_) {
700+
dateFilter = _dateFilter_;
701+
today = new Date();
702+
element = $compile('<datepicker></datepicker>')($rootScope);
703+
$rootScope.$digest();
704+
}));
705+
706+
it('should work without model on day-mode', function() {
707+
var title = dateFilter(today, 'MMMM yyyy');
708+
expect(getTitle()).toBe(title);
709+
});
710+
711+
it('should work without model on month-mode', function() {
712+
clickTitleButton();
713+
var title = dateFilter(today, 'yyyy');
714+
expect(getTitle()).toBe(title);
715+
});
696716

717+
it('should work without model on year-mode', function() {
718+
clickTitleButton();
719+
clickTitleButton();
720+
721+
// Simulate datepicker's algorithm for year ranges
722+
var start = parseInt((today.getFullYear() - 1) / 20, 10) * 20 + 1;
723+
var end = start + 19; // The default range is 20;
724+
var title = start + ' - ' + end;
725+
726+
expect(getTitle()).toBe(title);
727+
});
728+
});
729+
697730
describe('attribute `starting-day`', function () {
698731
beforeEach(function() {
699732
$rootScope.startingDay = 1;

0 commit comments

Comments
 (0)