From ad8624120554df5ced20139342ef918a34887471 Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Mon, 8 Sep 2014 00:08:27 +0200 Subject: [PATCH] fix(input): set ngTrueValue on required checkbox Fixes #5164 --- src/ng/directive/input.js | 4 ++-- test/ng/directive/inputSpec.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 6328420f460d..c100d8449412 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1253,9 +1253,9 @@ function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filt element[0].checked = ctrl.$viewValue; }; - // Override the standard `$isEmpty` because a value of `false` means empty in a checkbox. + // Override the standard `$isEmpty` because an empty checkbox is always set to `false` ctrl.$isEmpty = function(value) { - return value !== trueValue; + return value === false; }; ctrl.$formatters.push(function(value) { diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index a239d4511d66..b80ffc067ad5 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -3623,7 +3623,7 @@ describe('input', function() { it('should be required if false', function() { - compileInput(''); + compileInput(''); browserTrigger(inputElm, 'click'); expect(inputElm[0].checked).toBe(true); @@ -3633,6 +3633,16 @@ describe('input', function() { expect(inputElm[0].checked).toBe(false); expect(inputElm).toBeInvalid(); }); + + it('should set the ngTrueValue when required directive is present', function() { + compileInput(''); + + expect(inputElm).toBeInvalid(); + + browserTrigger(inputElm, 'click'); + expect(inputElm[0].checked).toBe(true); + expect(inputElm).toBeValid(); + }); });