Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngModelOptions debounce was failing when on event with a value of 0 #7205

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1822,9 +1822,20 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
* @param {string} trigger Event that triggered the update.
*/
this.$setViewValue = function(value, trigger) {
var debounceDelay = ctrl.$options && (isObject(ctrl.$options.debounce)
? (ctrl.$options.debounce[trigger] || ctrl.$options.debounce['default'] || 0)
: ctrl.$options.debounce) || 0;
var debounceDelay = 0,
options = ctrl.$options,
debounce;

if(options && isDefined(options.debounce)) {
debounce = options.debounce;
if(isNumber(debounce)) {
debounceDelay = debounce;
} else if(isNumber(debounce[trigger])) {
debounceDelay = debounce[trigger];
} else if (isNumber(debounce['default'])) {
debounceDelay = debounce['default'];
}
}

$timeout.cancel(pendingDebounce);
if (debounceDelay) {
Expand Down
19 changes: 19 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,25 @@ describe('input', function() {
expect(scope.checkbox).toBe(false);
}));

it('should allow selecting 0 for non-default debounce timeouts for each event on checkboxes', inject(function($timeout) {
compileInput('<input type="checkbox" ng-model="checkbox" '+
'ng-model-options="{ '+
'updateOn: \'default blur\', debounce: { default: 10000, blur: 0 } }"'+
'/>');

inputElm[0].checked = false;
browserTrigger(inputElm, 'click');
expect(scope.checkbox).toBe(undefined);
$timeout.flush(8000);
expect(scope.checkbox).toBe(undefined);
$timeout.flush(3000);
expect(scope.checkbox).toBe(true);
inputElm[0].checked = true;
browserTrigger(inputElm, 'click');
browserTrigger(inputElm, 'blur');
$timeout.flush(0);
expect(scope.checkbox).toBe(false);
}));

it('should inherit model update settings from ancestor elements', inject(function($timeout) {
var doc = $compile(
Expand Down