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

Commit

Permalink
fix(datepicker): alternate input formats: update the datepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
davious committed Dec 5, 2015
1 parent c0f1027 commit bdab729
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
for (var i = 0; i < altInputFormats.length; i++) {
date = dateParser.parse(viewValue, altInputFormats[i], scope.date);
if (!isNaN(date)) {
ngModel.$setViewValue(date);
break;
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2343,10 +2343,10 @@ describe('datepicker', function() {
describe('datepickerPopupConfig.altInputFormats', function() {
var originalConfig = {};
beforeEach(inject(function(uibDatepickerPopupConfig) {
$rootScope.date = new Date('November 9, 1980');
angular.extend(originalConfig, uibDatepickerPopupConfig);
uibDatepickerPopupConfig.datepickerPopup = 'MM-dd-yyyy';
uibDatepickerPopupConfig.altInputFormats = ['M!/d!/yyyy'];

var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup is-open="true"></div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
Expand All @@ -2364,6 +2364,12 @@ describe('datepicker', function() {
expect($rootScope.date.getMonth()).toEqual(10);
expect($rootScope.date.getDate()).toEqual(8);
});

it('changes the datepicker', function() {
expect(selectedElementIndex()).toEqual(14);
changeInputValueTo(inputEl, '11/8/1980');
expect(selectedElementIndex()).toEqual(13);
});
});

describe('attribute `alt-input-formats`', function() {
Expand All @@ -2381,6 +2387,12 @@ describe('datepicker', function() {
expect($rootScope.date.getMonth()).toEqual(10);
expect($rootScope.date.getDate()).toEqual(8);
});

it('changes the datepicker', function() {
expect(selectedElementIndex()).toEqual(14);
changeInputValueTo(inputEl, '11/8/1980');
expect(selectedElementIndex()).toEqual(13);
});
});
});

Expand Down

0 comments on commit bdab729

Please sign in to comment.