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

Commit

Permalink
fix(date): Prevent jquery datepicker formatDate exception
Browse files Browse the repository at this point in the history
fixes #48
  • Loading branch information
alexanderchan committed Dec 3, 2015
1 parent be36298 commit 10c0e54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ before_install:

#script: "grunt"
sudo: false

cache:
directories:
- node_modules
6 changes: 5 additions & 1 deletion src/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex
dateFormat = dateFormat || uiDateFormatConfig;
if (value) {
if (dateFormat) {
return jQuery.datepicker.formatDate(dateFormat, value);
try {
return jQuery.datepicker.formatDate(dateFormat, value);
} catch (formatException) {
return undefined;
}
}

if (value.toISOString) {
Expand Down
11 changes: 11 additions & 0 deletions test/date.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,17 @@ describe('uiDateFormat', function() {
});
});

it('should not throw when a user types in an incomplete value', function() {
inject(function($compile, $rootScope) {
var element = $compile('<input ui-date-format="yy-mm-dd" ng-model="x"/>')($rootScope);
var ngModel = element.controller('ngModel');
expect(function incompleteValue() {
ngModel.$setViewValue('2015-');
}).not.toThrow();
expect(ngModel.$modelValue).toBeUndefined();
});
});

it('should convert empty strings to null', inject(function($compile, $rootScope) {
var element = $compile('<input ui-date-format ng-model="x">')($rootScope);
element.controller('ngModel').$setViewValue('');
Expand Down

0 comments on commit 10c0e54

Please sign in to comment.