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

Commit e0eb1bc

Browse files
committed
fix(datepicker): parse input using dateParser
Fixes #1289 Closes #2085
1 parent bd2ae0e commit e0eb1bc

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/datepicker/datepicker.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position'])
1+
angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position'])
22

33
.constant('datepickerConfig', {
44
formatDay: 'dd',
@@ -430,8 +430,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position'])
430430
showButtonBar: true
431431
})
432432

433-
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'datepickerPopupConfig',
434-
function ($compile, $parse, $document, $position, dateFilter, datepickerPopupConfig) {
433+
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig',
434+
function ($compile, $parse, $document, $position, dateFilter, dateParser, datepickerPopupConfig) {
435435
return {
436436
restrict: 'EA',
437437
require: 'ngModel',
@@ -489,7 +489,6 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
489489
datepickerEl.attr('date-disabled', 'dateDisabled({ date: date, mode: mode })');
490490
}
491491

492-
// TODO: reverse from dateFilter string to Date object
493492
function parseDate(viewValue) {
494493
if (!viewValue) {
495494
ngModel.$setValidity('date', true);
@@ -498,7 +497,7 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
498497
ngModel.$setValidity('date', true);
499498
return viewValue;
500499
} else if (angular.isString(viewValue)) {
501-
var date = new Date(viewValue);
500+
var date = dateParser.parse(viewValue, dateFormat) || new Date(viewValue);
502501
if (isNaN(date)) {
503502
ngModel.$setValidity('date', false);
504503
return undefined;

src/datepicker/docs/demo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ var DatepickerDemoCtrl = function ($scope) {
3131
};
3232

3333
$scope.initDate = new Date('2016-15-20');
34-
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'shortDate'];
34+
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
3535
$scope.format = $scope.formats[0];
3636
};

src/datepicker/test/datepicker.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,19 @@ describe('datepicker directive', function () {
13511351
});
13521352
});
13531353

1354+
describe('european format', function () {
1355+
it('dd.MM.yyyy', function() {
1356+
var wrapElement = $compile('<div><input ng-model="date" datepicker-popup="dd.MM.yyyy"><div>')($rootScope);
1357+
$rootScope.$digest();
1358+
assignElements(wrapElement);
1359+
1360+
changeInputValueTo(inputEl, '11.08.2013');
1361+
expect($rootScope.date.getFullYear()).toEqual(2013);
1362+
expect($rootScope.date.getMonth()).toEqual(7);
1363+
expect($rootScope.date.getDate()).toEqual(11);
1364+
});
1365+
});
1366+
13541367
describe('`close-on-date-selection` attribute', function () {
13551368
beforeEach(inject(function() {
13561369
$rootScope.close = false;

0 commit comments

Comments
 (0)