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

fix(datepicker): active date should be model if present #5082

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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