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

fix(datepickerPopup): altInputFormats(closes #6623) #6624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/datepickerPopup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
}
}
});
$attrs.$observe('altInputFormats', function(value, oldValue) {
var newAltInputFormats = angular.isDefined(value) ? $scope.$parent.$eval(value) : altInputFormats;

if (newAltInputFormats !== altInputFormats) {
altInputFormats = newAltInputFormats;
}
});
}

if (!dateFormat) {
Expand Down
14 changes: 13 additions & 1 deletion src/datepickerPopup/test/popup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,8 @@ describe('datepicker popup', function() {
describe('attribute `alt-input-formats`', function() {
beforeEach(function() {
$rootScope.date = new Date('November 9, 1980');
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup="MMMM d yyyy" alt-input-formats="[\'M!/d!/yyyy\']" is-open="true"></div>')($rootScope);
$rootScope.altInputFormats = ['M!/d!/yyyy'];
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup="MMMM d yyyy" alt-input-formats="altInputFormats" is-open="true"></div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
});
Expand All @@ -1532,6 +1533,17 @@ describe('datepicker popup', function() {
changeInputValueTo(inputEl, '11/8/1980');
expect(selectedElementIndex()).toEqual(13);
});

it('changes alternate input formats', function() {
$rootScope.altInputFormats = ['yyyy-M!-d!'];
$timeout(function() {
changeInputValueTo(inputEl, '2017-08-30');

expect($rootScope.date.getFullYear()).toEqual(2017);
expect($rootScope.date.getMonth()).toEqual(7);
expect($rootScope.date.getDate()).toEqual(30);
}, 0);
});
});
});

Expand Down