From ba543b05d814dd054904ce30b9c42b381809b446 Mon Sep 17 00:00:00 2001 From: Martin Thorsen Ranang Date: Wed, 7 Jan 2015 23:28:10 +0100 Subject: [PATCH] fix(ngModelOptions): Allow sharing ngModelOptions objects between multiple directive instances, even when they specify default behavior. --- src/ng/directive/ngModel.js | 2 +- test/ng/directive/ngModelSpec.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/ngModel.js b/src/ng/directive/ngModel.js index 44cfdbddabfe..5ef9bc577d10 100644 --- a/src/ng/directive/ngModel.js +++ b/src/ng/directive/ngModel.js @@ -1218,7 +1218,7 @@ var ngModelOptionsDirective = function() { this.$options = $scope.$eval($attrs.ngModelOptions); // Allow adding/overriding bound events if (this.$options.updateOn !== undefined) { - this.$options.updateOnDefault = false; + this.$options.updateOnDefault = this.$options.updateOnDefault || false; // extract "default" pseudo-event from list of events that can trigger a model update this.$options.updateOn = trim(this.$options.updateOn.replace(DEFAULT_REGEXP, function() { that.$options.updateOnDefault = true; diff --git a/test/ng/directive/ngModelSpec.js b/test/ng/directive/ngModelSpec.js index dfa20a75dd0f..1d902dd6797c 100644 --- a/test/ng/directive/ngModelSpec.js +++ b/test/ng/directive/ngModelSpec.js @@ -1733,6 +1733,31 @@ describe('ngModelOptions attributes', function() { }); + it('should allow options object with default update behavior to be shared between instances', function() { + $rootScope.sharedModelOptions = { + updateOn: 'default blur' + }; + + var inputElm = helper.compileInput( + '' + + ''), + inputA = jqLite(inputElm[0]), + inputB = jqLite(inputElm[1]); + + expect($rootScope.sharedModelOptions.updateOnDefault).toBe(true); + helper.changeGivenInputTo(inputA, 'a'); + expect($rootScope.nameA).toEqual('a'); + helper.changeGivenInputTo(inputB, 'b'); + expect($rootScope.nameB).toEqual('b'); + + delete $rootScope.sharedModelOptions; + }); + + it('should allow overriding the model update trigger event on checkboxes', function() { var inputElm = helper.compileInput( '