From e35c6896f0625ed65121f8ed7a193a4c25b59aaf Mon Sep 17 00:00:00 2001 From: Tamer Aydin Date: Fri, 31 Jan 2014 00:28:26 +0100 Subject: [PATCH] fix(input): ng-required conflicts with vg-true-value Before this change, overridden "isEmpty" method which is called in "requiredDirective" would return a wrong result when the parameter is given as "true". This change corrects the statement value within method. Closes #5164 --- src/ng/directive/input.js | 2 +- test/ng/directive/inputSpec.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 27813a4686c0..a20d0b5fadb0 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -673,7 +673,7 @@ function checkboxInputType(scope, element, attr, ctrl) { // Override the standard `$isEmpty` because a value of `false` means empty in a checkbox. ctrl.$isEmpty = function(value) { - return value !== trueValue; + return value !== true; }; ctrl.$formatters.push(function(value) { diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 668fa0b54a1e..ccf6697e8528 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -1111,6 +1111,37 @@ describe('input', function() { expect(inputElm[0].checked).toBe(false); expect(inputElm).toBeInvalid(); }); + + it('should allow custom enumaration even if it is required', function() { + compileInput(''); + + scope.$apply(function() { + scope.name = 'y'; + }); + expect(inputElm[0].checked).toBe(true); + expect(inputElm).toBeValid(); + + scope.$apply(function() { + scope.name = 'n'; + }); + expect(inputElm[0].checked).toBe(false); + expect(inputElm).toBeInvalid(); + + scope.$apply(function() { + scope.name = 'something else'; + }); + expect(inputElm[0].checked).toBe(false); + expect(inputElm).toBeInvalid(); + + browserTrigger(inputElm, 'click'); + expect(scope.name).toEqual('y'); + expect(inputElm).toBeValid(); + + browserTrigger(inputElm, 'click'); + expect(scope.name).toEqual('n'); + expect(inputElm).toBeInvalid(); + }); });