diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 408160521271..71f49ddf34e0 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1472,7 +1472,7 @@ function radioInputType(scope, element, attr, ctrl) { } }; - element.on('click', listener); + element.on('change', listener); ctrl.$render = function() { var value = attr.value; @@ -1505,7 +1505,7 @@ function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filt ctrl.$setViewValue(element[0].checked, ev && ev.type); }; - element.on('click', listener); + element.on('change', listener); ctrl.$render = function() { element[0].checked = ctrl.$viewValue; diff --git a/test/helpers/testabilityPatch.js b/test/helpers/testabilityPatch.js index c432f8ee0920..f6939b1e24f5 100644 --- a/test/helpers/testabilityPatch.js +++ b/test/helpers/testabilityPatch.js @@ -359,7 +359,7 @@ function generateInputCompilerHelper(helper) { }; }); }); - inject(function($compile, $rootScope, $sniffer) { + inject(function($compile, $rootScope, $sniffer, $document, $rootElement) { helper.compileInput = function(inputHtml, mockValidity, scope) { @@ -381,6 +381,9 @@ function generateInputCompilerHelper(helper) { // Compile the lot and return the input element $compile(helper.formElm)(scope); + $rootElement.append(helper.formElm); + jqLite($document[0].body).append($rootElement); + spyOn(scope.form, '$addControl').and.callThrough(); spyOn(scope.form, '$$renameControl').and.callThrough(); diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index db53047ec6cc..d09671d46329 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -2932,7 +2932,7 @@ describe('input', function() { describe('radio', function() { - it('should update the model', function() { + they('should update the model on $prop event', ['click', 'change'], function(event) { var inputElm = helper.compileInput( '' + '' + @@ -2948,7 +2948,8 @@ describe('input', function() { expect(inputElm[1].checked).toBe(true); expect(inputElm[2].checked).toBe(false); - browserTrigger(inputElm[2], 'click'); + if (event === 'change') inputElm[2].checked = true; + browserTrigger(inputElm[2], event); expect($rootScope.color).toBe('blue'); }); @@ -3005,6 +3006,23 @@ describe('input', function() { }); + they('should update the model on $prop event', ['click', 'change'], function(event) { + var inputElm = helper.compileInput(''); + + expect(inputElm[0].checked).toBe(false); + + $rootScope.$apply("checkbox = true"); + expect(inputElm[0].checked).toBe(true); + + $rootScope.$apply("checkbox = false"); + expect(inputElm[0].checked).toBe(false); + + if (event === 'change') inputElm[0].checked = true; + browserTrigger(inputElm[0], event); + expect($rootScope.checkbox).toBe(true); + }); + + it('should format booleans', function() { var inputElm = helper.compileInput('');