Skip to content

Commit

Permalink
fix(datepicker): Manually appliying angular-ui#1913 to 0\.11 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Albino authored and Alex Albino committed May 9, 2014
1 parent 42cc3f2 commit a10a2d4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
if ( this.element ) {
this._refreshView();

var date = ngModelCtrl.$modelValue ? new Date(ngModelCtrl.$modelValue) : null;
ngModelCtrl.$setValidity('date-disabled', !date || (this.element && !this.isDisabled(date)));
if (ngModelCtrl.$modelValue) {
var date = ngModelCtrl.$modelValue ? new Date(ngModelCtrl.$modelValue) : null;
ngModelCtrl.$setValidity('date-disabled', !date || (this.element && !this.isDisabled(date)));
}
}
};

Expand Down
33 changes: 33 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,40 @@ describe('datepicker directive', function () {
});

});

describe('attribute `ng-model`', function() {
var dateFilter, today;
beforeEach(inject(function(_dateFilter_) {
dateFilter = _dateFilter_;
today = new Date();
element = $compile('<datepicker></datepicker>')($rootScope);
$rootScope.$digest();
}));

it('should work without model on day-mode', function() {
var title = dateFilter(today, 'MMMM yyyy');
expect(getTitle()).toBe(title);
});

it('should work without model on month-mode', function() {
clickTitleButton();
var title = dateFilter(today, 'yyyy');
expect(getTitle()).toBe(title);
});

it('should work without model on year-mode', function() {
clickTitleButton();
clickTitleButton();

// Simulate datepicker's algorithm for year ranges
var start = parseInt((today.getFullYear() - 1) / 20, 10) * 20 + 1;
var end = start + 19; // The default range is 20;
var title = start + ' - ' + end;

expect(getTitle()).toBe(title);
});
});

describe('attribute `starting-day`', function () {
beforeEach(function() {
$rootScope.startingDay = 1;
Expand Down

0 comments on commit a10a2d4

Please sign in to comment.