diff --git a/.gitignore b/.gitignore index 6716155984..21835254a9 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ lib-cov *.swo .DS_Store .idea +.vscode pids logs diff --git a/src/datepickerPopup/popup.js b/src/datepickerPopup/popup.js index 02c0e88a1c..22a24a9806 100644 --- a/src/datepickerPopup/popup.js +++ b/src/datepickerPopup/popup.js @@ -125,11 +125,22 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ $scope.date = dateParser.fromTimezone(value, ngModelOptions.getOption('timezone')); + if (ngModelOptions.getOption('allowInvalid') && isNaN($scope.date)) { + $scope.date = value; + return value; + } + return dateParser.filter($scope.date, dateFormat); }); } else { ngModel.$formatters.push(function(value) { $scope.date = dateParser.fromTimezone(value, ngModelOptions.getOption('timezone')); + + if (ngModelOptions.getOption('allowInvalid') && isNaN($scope.date)) { + $scope.date = value; + return value; + } + return value; }); } @@ -191,7 +202,7 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ } else if (angular.isDate($scope.datepickerOptions[key])) { dates[key] = new Date($scope.datepickerOptions[key]); } else { - if ($datepickerPopupLiteralWarning) { + if ($datepickerPopupLiteralWarning && !ngModelOptions.getOption('allowInvalid')) { $log.warn('Literal date support has been deprecated, please switch to date object usage'); } diff --git a/src/datepickerPopup/test/popup.spec.js b/src/datepickerPopup/test/popup.spec.js index 227fdb3596..1830521c85 100644 --- a/src/datepickerPopup/test/popup.spec.js +++ b/src/datepickerPopup/test/popup.spec.js @@ -580,6 +580,31 @@ describe('datepicker popup', function() { }); }); + describe('works with ngModelOptions allowInvalid', function() { + var $timeout, wrapElement; + + beforeEach(inject(function(_$document_, _$sniffer_, _$timeout_) { + $document = _$document_; + $timeout = _$timeout_; + $rootScope.date = 'Invalid Date'; + wrapElement = $compile('
')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + })); + + it('should initially display invalid date', function() { + expect(inputEl.val()).toEqual('Invalid Date'); + }); + + it('should display invalid date on change', function(){ + $rootScope.date = 'Another Invalid Date'; + $rootScope.$digest(); + expect(inputEl.val()).toEqual('Another Invalid Date'); + }); + }); + describe('attribute `datepickerOptions`', function() { describe('show-weeks', function() { beforeEach(function() {