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

Commit

Permalink
fix(datepicker): Make datepicker respect dateFormat inside ng-if
Browse files Browse the repository at this point in the history
Makes the datepicker respect dateFormat inside ng-if.
It turns out this case didn't fail in angular 1.2 but is necessitated
(along with several other fixes) by angular 1.3 not having the
$viewValue still be a proper Date().  So this patch only covers a piece
of the puzzle.
  • Loading branch information
hamfastgamgee authored and wesleycho committed Mar 23, 2015
1 parent b5f220f commit e373941
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/datepicker/datepicker.js
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Expand Up @@ -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('<div><div ng-if="true"><input ng-model="date" datepicker-popup></div></div>')($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;

Expand Down

0 comments on commit e373941

Please sign in to comment.