From 9019298cc37e9fa361692da1e8ddbaed4952d9ad Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Tue, 15 Dec 2015 21:59:24 -0500 Subject: [PATCH] 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 --- src/datepicker/datepicker.js | 4 ++++ src/datepicker/test/datepicker.spec.js | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 0716a926b9..9baaa78736 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -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(); }; diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 0f295f2ced..19be95da52 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -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('')($rootScope); @@ -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); });