Skip to content

Commit 12a682e

Browse files
Merge pull request #32 from angular/master
Update upstream
2 parents c6c5894 + 55ba449 commit 12a682e

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/ng/directive/ngModel.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,12 @@ NgModelController.prototype = {
838838

839839
if (isNumber(debounceDelay[trigger])) {
840840
debounceDelay = debounceDelay[trigger];
841-
} else if (isNumber(debounceDelay['default'])) {
841+
} else if (isNumber(debounceDelay['default']) &&
842+
this.$options.getOption('updateOn').indexOf(trigger) === -1
843+
) {
842844
debounceDelay = debounceDelay['default'];
845+
} else if (isNumber(debounceDelay['*'])) {
846+
debounceDelay = debounceDelay['*'];
843847
}
844848

845849
this.$$timeout.cancel(this.$$pendingDebounce);

src/ng/directive/ngModelOptions.js

+8
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ defaultModelOptions = new ModelOptions({
321321
* debounce: { 'default': 500, 'blur': 0 }
322322
* }"
323323
* ```
324+
* You can use the `*` key to specify a debounce value that applies to all events that are not
325+
* specifically listed. In the following example, `mouseup` would have a debounce delay of 1000:
326+
* ```
327+
* ng-model-options="{
328+
* updateOn: 'default blur mouseup',
329+
* debounce: { 'default': 500, 'blur': 0, '*': 1000 }
330+
* }"
331+
* ```
324332
* - `allowInvalid`: boolean value which indicates that the model can be set with values that did
325333
* not validate correctly instead of the default behavior of setting the model to undefined.
326334
* - `getterSetter`: boolean value which determines whether or not to treat functions bound to

test/ng/directive/ngModelOptionsSpec.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,41 @@ describe('ngModelOptions', function() {
498498

499499
helper.changeInputValueTo('c');
500500
browserTrigger(helper.inputElm, 'mouseup');
501-
// counter-intuitively `default` in `debounce` is a catch-all
501+
// `default` in `debounce` only affects the event triggers that are not defined in updateOn
502+
expect($rootScope.name).toEqual('c');
503+
});
504+
505+
506+
it('should use the value of * to debounce all unspecified events',
507+
function() {
508+
var inputElm = helper.compileInput(
509+
'<input type="text" ng-model="name" name="alias" ' +
510+
'ng-model-options="{' +
511+
'updateOn: \'default blur mouseup\', ' +
512+
'debounce: { default: 10000, blur: 5000, \'*\': 15000 }' +
513+
'}"' +
514+
'/>');
515+
516+
helper.changeInputValueTo('a');
517+
expect($rootScope.name).toBeUndefined();
518+
$timeout.flush(6000);
519+
expect($rootScope.name).toBeUndefined();
520+
$timeout.flush(4000);
521+
expect($rootScope.name).toEqual('a');
522+
523+
helper.changeInputValueTo('b');
524+
browserTrigger(inputElm, 'blur');
525+
$timeout.flush(4000);
526+
expect($rootScope.name).toEqual('a');
527+
$timeout.flush(2000);
502528
expect($rootScope.name).toEqual('b');
503-
$timeout.flush(10000);
529+
530+
helper.changeInputValueTo('c');
531+
browserTrigger(helper.inputElm, 'mouseup');
532+
expect($rootScope.name).toEqual('b');
533+
$timeout.flush(10000); // flush default
534+
expect($rootScope.name).toEqual('b');
535+
$timeout.flush(5000);
504536
expect($rootScope.name).toEqual('c');
505537
});
506538

0 commit comments

Comments
 (0)