Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(datepicker): active date should be model if present
Browse files Browse the repository at this point in the history
- When ng-model value is initially present, it should set the active date to be the model date as per documentation

Closes #5082
Fixes #5081
  • Loading branch information
wesleycho committed Dec 16, 2015
1 parent 2635f0d commit 9019298
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
this.init = function(ngModelCtrl_) {
ngModelCtrl = ngModelCtrl_;

if (ngModelCtrl.$modelValue) {
this.activeDate = ngModelCtrl.$modelValue;
}

ngModelCtrl.$render = function() {
self.render();
};
Expand Down
24 changes: 24 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ describe('datepicker', function() {
$templateCache = _$templateCache_;
}));

describe('with no initial date', function() {
beforeEach(function() {
jasmine.clock().install();
});

afterEach(function() {
jasmine.clock().uninstall();
});

it('should have an active date equal to the current date', function() {
var baseTime = new Date(2015, 2, 23);
jasmine.clock().mockDate(baseTime);

element = $compile('<uib-datepicker ng-model="fooDate"></uib-datepicker')($rootScope);
$rootScope.$digest();

expect(element.controller('uibDatepicker').activeDate.getTime()).toEqual(baseTime.getTime());
});
});

describe('basic functionality', function() {
beforeEach(function() {
element = $compile('<uib-datepicker ng-model="date"></uib-datepicker>')($rootScope);
Expand Down Expand Up @@ -243,6 +263,10 @@ describe('datepicker', function() {
expect($rootScope.date).toEqual(new Date('September 30, 2010 15:30:00'));
});

it('has activeDate value of model', function() {
expect(element.controller('uibDatepicker').activeDate).toEqual(new Date('September 30, 2010 15:30:00'));
});

it('has `selected` only the correct day', function() {
expectSelectedElement(32);
});
Expand Down

0 comments on commit 9019298

Please sign in to comment.