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

Commit 789790f

Browse files
fix(ngModelOptions): handle update triggers that are not in debounce list
Closes #15401
1 parent fd1a93a commit 789790f

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/ng/directive/ngModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ NgModelController.prototype = {
818818

819819
this.$$timeout.cancel(this.$$pendingDebounce);
820820
var that = this;
821-
if (debounceDelay) {
821+
if (debounceDelay > 0) { // this fails if debounceDelay is an object
822822
this.$$pendingDebounce = this.$$timeout(function() {
823823
that.$commitViewValue();
824824
}, debounceDelay);

test/ng/directive/ngModelOptionsSpec.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,26 +469,52 @@ describe('ngModelOptions', function() {
469469
var inputElm = helper.compileInput(
470470
'<input type="text" ng-model="name" name="alias" ' +
471471
'ng-model-options="{' +
472-
'updateOn: \'default blur\', ' +
472+
'updateOn: \'default blur mouseup\', ' +
473473
'debounce: { default: 10000, blur: 5000 }' +
474474
'}"' +
475475
'/>');
476476

477477
helper.changeInputValueTo('a');
478-
expect($rootScope.checkbox).toBeUndefined();
478+
expect($rootScope.name).toBeUndefined();
479479
$timeout.flush(6000);
480-
expect($rootScope.checkbox).toBeUndefined();
480+
expect($rootScope.name).toBeUndefined();
481481
$timeout.flush(4000);
482482
expect($rootScope.name).toEqual('a');
483+
483484
helper.changeInputValueTo('b');
484485
browserTrigger(inputElm, 'blur');
485486
$timeout.flush(4000);
486487
expect($rootScope.name).toEqual('a');
487488
$timeout.flush(2000);
488489
expect($rootScope.name).toEqual('b');
490+
491+
helper.changeInputValueTo('c');
492+
browserTrigger(helper.inputElm, 'mouseup');
493+
// counter-intuitively `default` in `debounce` is a catch-all
494+
expect($rootScope.name).toEqual('b');
495+
$timeout.flush(10000);
496+
expect($rootScope.name).toEqual('c');
489497
});
490498

491499

500+
it('should trigger immediately for the event if not listed in the debounce list',
501+
function() {
502+
var inputElm = helper.compileInput(
503+
'<input type="text" ng-model="name" name="alias" ' +
504+
'ng-model-options="{' +
505+
'updateOn: \'default blur foo\', ' +
506+
'debounce: { blur: 5000 }' +
507+
'}"' +
508+
'/>');
509+
510+
helper.changeInputValueTo('a');
511+
expect($rootScope.name).toEqual('a');
512+
513+
helper.changeInputValueTo('b');
514+
browserTrigger(inputElm, 'foo');
515+
expect($rootScope.name).toEqual('b');
516+
});
517+
492518
it('should allow selecting different debounce timeouts for each event on checkboxes', function() {
493519
var inputElm = helper.compileInput('<input type="checkbox" ng-model="checkbox" ' +
494520
'ng-model-options="{ ' +

0 commit comments

Comments
 (0)