Skip to content

Commit

Permalink
feat(datepicker): ng-model-options: allowInvalid support, angular-ui#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Barrus committed Dec 10, 2015
1 parent 3658502 commit 5221901
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,14 +826,12 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi

if (angular.isString(viewValue)) {
var date = parseDateString(viewValue);
if (isNaN(date)) {
return undefined;
if (!isNaN(date)) {
return date;
}

return date;
}

return undefined;
return ngModel.$options && ngModel.$options.allowInvalid ? viewValue : undefined;
}

function validator(modelValue, viewValue) {
Expand Down
5 changes: 5 additions & 0 deletions src/datepicker/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ The datepicker has 3 modes:
* `year-range`
_(Default: `20`)_ -
Number of years displayed in year selection.

* `ng-model-options`
_(Default: {})_ -
allowInvalid support. [More on ngModelOptions](https://docs.angularjs.org/api/ng/directive/ngModelOptions).


### uib-datepicker-popup settings ###

Expand Down
27 changes: 27 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,33 @@ describe('datepicker', function() {
});
});

describe('ngModelOptions allowInvalid', function() {
var $sniffer, inputEl;

function changeInputValueTo(el, value) {
el.val(value);
el.trigger($sniffer.hasEvent('input') ? 'input' : 'change');
$rootScope.$digest();
}

beforeEach(inject(function(_$sniffer_) {
$sniffer = _$sniffer_;

$rootScope.date = new Date('September 30, 2010 15:30:00');
$rootScope.modelOptions = {allowInvalid: true};
element = $compile('<div><input ng-model="date" ng-model-options="modelOptions" uib-datepicker-popup></div>')($rootScope);
inputEl = element.find('input');
$rootScope.$digest();
}));


it('should update ng-model even if the date is invalid when allowInvalid is true', function() {
changeInputValueTo(inputEl, 'pizza');
expect($rootScope.date).toBe('pizza');
expect(inputEl.val()).toBe('pizza');
});
});

describe('setting datepickerPopupConfig', function() {
var originalConfig = {};
beforeEach(inject(function(uibDatepickerPopupConfig) {
Expand Down

0 comments on commit 5221901

Please sign in to comment.