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

Commit 9019298

Browse files
committed
fix(datepicker): active date should be model if present
- 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
1 parent 2635f0d commit 9019298

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/datepicker/datepicker.js

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
9898
this.init = function(ngModelCtrl_) {
9999
ngModelCtrl = ngModelCtrl_;
100100

101+
if (ngModelCtrl.$modelValue) {
102+
this.activeDate = ngModelCtrl.$modelValue;
103+
}
104+
101105
ngModelCtrl.$render = function() {
102106
self.render();
103107
};

src/datepicker/test/datepicker.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ describe('datepicker', function() {
205205
$templateCache = _$templateCache_;
206206
}));
207207

208+
describe('with no initial date', function() {
209+
beforeEach(function() {
210+
jasmine.clock().install();
211+
});
212+
213+
afterEach(function() {
214+
jasmine.clock().uninstall();
215+
});
216+
217+
it('should have an active date equal to the current date', function() {
218+
var baseTime = new Date(2015, 2, 23);
219+
jasmine.clock().mockDate(baseTime);
220+
221+
element = $compile('<uib-datepicker ng-model="fooDate"></uib-datepicker')($rootScope);
222+
$rootScope.$digest();
223+
224+
expect(element.controller('uibDatepicker').activeDate.getTime()).toEqual(baseTime.getTime());
225+
});
226+
});
227+
208228
describe('basic functionality', function() {
209229
beforeEach(function() {
210230
element = $compile('<uib-datepicker ng-model="date"></uib-datepicker>')($rootScope);
@@ -243,6 +263,10 @@ describe('datepicker', function() {
243263
expect($rootScope.date).toEqual(new Date('September 30, 2010 15:30:00'));
244264
});
245265

266+
it('has activeDate value of model', function() {
267+
expect(element.controller('uibDatepicker').activeDate).toEqual(new Date('September 30, 2010 15:30:00'));
268+
});
269+
246270
it('has `selected` only the correct day', function() {
247271
expectSelectedElement(32);
248272
});

0 commit comments

Comments
 (0)