Skip to content

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.
  • Loading branch information
hamfastgamgee authored and ayakovlevgh committed Mar 24, 2015
1 parent 85a11d9 commit c761ca8
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 c761ca8

Please sign in to comment.