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

Commit 00513e7

Browse files
committed
fix(datepicker): alternate input formats: setViewValue on parse
1 parent c0f1027 commit 00513e7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: src/datepicker/datepicker.js

+1
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
817817
for (var i = 0; i < altInputFormats.length; i++) {
818818
date = dateParser.parse(viewValue, altInputFormats[i], scope.date);
819819
if (!isNaN(date)) {
820+
ngModel.$setViewValue(date);
820821
break;
821822
}
822823
}

Diff for: src/datepicker/test/datepicker.spec.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -2343,10 +2343,10 @@ describe('datepicker', function() {
23432343
describe('datepickerPopupConfig.altInputFormats', function() {
23442344
var originalConfig = {};
23452345
beforeEach(inject(function(uibDatepickerPopupConfig) {
2346+
$rootScope.date = new Date('November 9, 1980');
23462347
angular.extend(originalConfig, uibDatepickerPopupConfig);
23472348
uibDatepickerPopupConfig.datepickerPopup = 'MM-dd-yyyy';
23482349
uibDatepickerPopupConfig.altInputFormats = ['M!/d!/yyyy'];
2349-
23502350
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup is-open="true"></div>')($rootScope);
23512351
$rootScope.$digest();
23522352
assignElements(wrapElement);
@@ -2364,6 +2364,12 @@ describe('datepicker', function() {
23642364
expect($rootScope.date.getMonth()).toEqual(10);
23652365
expect($rootScope.date.getDate()).toEqual(8);
23662366
});
2367+
2368+
it('changes the datepicker', function() {
2369+
expect(selectedElementIndex()).toEqual(14);
2370+
changeInputValueTo(inputEl, '11/8/1980');
2371+
expect(selectedElementIndex()).toEqual(13);
2372+
});
23672373
});
23682374

23692375
describe('attribute `alt-input-formats`', function() {
@@ -2381,6 +2387,12 @@ describe('datepicker', function() {
23812387
expect($rootScope.date.getMonth()).toEqual(10);
23822388
expect($rootScope.date.getDate()).toEqual(8);
23832389
});
2390+
2391+
it('changes the datepicker', function() {
2392+
expect(selectedElementIndex()).toEqual(14);
2393+
changeInputValueTo(inputEl, '11/8/1980');
2394+
expect(selectedElementIndex()).toEqual(13);
2395+
});
23842396
});
23852397
});
23862398

0 commit comments

Comments
 (0)