From 2c2dba6d145c95500efe7f6be6248d56ae1aebee Mon Sep 17 00:00:00 2001 From: hamfastgamgee Date: Tue, 13 Jan 2015 12:31:26 -0600 Subject: [PATCH] fix(datepicker): Make datepicker respect dateFormat inside ng-if Makes the datepicker respect dateFormat inside ng-if. --- src/datepicker/datepicker.js | 10 ++++++---- src/datepicker/test/datepicker.spec.js | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 021ce60ef0..56f4734c6e 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -554,10 +554,12 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi }); // Outer change - ngModel.$render = function() { - var date = ngModel.$viewValue ? dateFilter(parseDate(ngModel.$viewValue), dateFormat) : ''; - element.val(date); - scope.date = parseDate( ngModel.$modelValue ); + ngModel.$render = function () { + if (dateFormat) { + var date = ngModel.$viewValue ? dateFilter(parseDate(ngModel.$viewValue), dateFormat) : ''; + element.val(date); + scope.date = parseDate( ngModel.$modelValue ); + } }; var documentClickBind = function(event) { diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 1a9f85d65c..a4558d155c 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1103,6 +1103,25 @@ describe('datepicker directive', function () { }); + describe('setting datepickerPopupConfig inside ng-if', function() { + var originalConfig = {}; + beforeEach(inject(function (datepickerPopupConfig) { + angular.extend(originalConfig, datepickerPopupConfig); + datepickerPopupConfig.datepickerPopup = 'MM-dd-yyyy'; + + element = $compile('
')($rootScope); + $rootScope.$digest(); + })); + afterEach(inject(function (datepickerPopupConfig) { + // return it to the original state + angular.extend(datepickerPopupConfig, originalConfig); + })); + + it('changes date format', function () { + expect(element.find('input').val()).toEqual('09-30-2010'); + }); + }); + describe('as popup', function () { var inputEl, dropdownEl, $document, $sniffer;