fix(ngModelOptions): handle update triggers that are not in debounce list
Closes #15401
This commit is contained in:
@@ -818,7 +818,7 @@ NgModelController.prototype = {
|
||||
|
||||
this.$$timeout.cancel(this.$$pendingDebounce);
|
||||
var that = this;
|
||||
if (debounceDelay) {
|
||||
if (debounceDelay > 0) { // this fails if debounceDelay is an object
|
||||
this.$$pendingDebounce = this.$$timeout(function() {
|
||||
that.$commitViewValue();
|
||||
}, debounceDelay);
|
||||
|
||||
@@ -469,26 +469,52 @@ describe('ngModelOptions', function() {
|
||||
var inputElm = helper.compileInput(
|
||||
'<input type="text" ng-model="name" name="alias" ' +
|
||||
'ng-model-options="{' +
|
||||
'updateOn: \'default blur\', ' +
|
||||
'updateOn: \'default blur mouseup\', ' +
|
||||
'debounce: { default: 10000, blur: 5000 }' +
|
||||
'}"' +
|
||||
'/>');
|
||||
|
||||
helper.changeInputValueTo('a');
|
||||
expect($rootScope.checkbox).toBeUndefined();
|
||||
expect($rootScope.name).toBeUndefined();
|
||||
$timeout.flush(6000);
|
||||
expect($rootScope.checkbox).toBeUndefined();
|
||||
expect($rootScope.name).toBeUndefined();
|
||||
$timeout.flush(4000);
|
||||
expect($rootScope.name).toEqual('a');
|
||||
|
||||
helper.changeInputValueTo('b');
|
||||
browserTrigger(inputElm, 'blur');
|
||||
$timeout.flush(4000);
|
||||
expect($rootScope.name).toEqual('a');
|
||||
$timeout.flush(2000);
|
||||
expect($rootScope.name).toEqual('b');
|
||||
|
||||
helper.changeInputValueTo('c');
|
||||
browserTrigger(helper.inputElm, 'mouseup');
|
||||
// counter-intuitively `default` in `debounce` is a catch-all
|
||||
expect($rootScope.name).toEqual('b');
|
||||
$timeout.flush(10000);
|
||||
expect($rootScope.name).toEqual('c');
|
||||
});
|
||||
|
||||
|
||||
it('should trigger immediately for the event if not listed in the debounce list',
|
||||
function() {
|
||||
var inputElm = helper.compileInput(
|
||||
'<input type="text" ng-model="name" name="alias" ' +
|
||||
'ng-model-options="{' +
|
||||
'updateOn: \'default blur foo\', ' +
|
||||
'debounce: { blur: 5000 }' +
|
||||
'}"' +
|
||||
'/>');
|
||||
|
||||
helper.changeInputValueTo('a');
|
||||
expect($rootScope.name).toEqual('a');
|
||||
|
||||
helper.changeInputValueTo('b');
|
||||
browserTrigger(inputElm, 'foo');
|
||||
expect($rootScope.name).toEqual('b');
|
||||
});
|
||||
|
||||
it('should allow selecting different debounce timeouts for each event on checkboxes', function() {
|
||||
var inputElm = helper.compileInput('<input type="checkbox" ng-model="checkbox" ' +
|
||||
'ng-model-options="{ ' +
|
||||
|
||||
Reference in New Issue
Block a user