Skip to content

Commit 1d47b0b

Browse files
committed
fix(input): set ngTrueValue on required checkbox
Fixes angular#5164
1 parent 9bedeb3 commit 1d47b0b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/ng/directive/input.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1253,9 +1253,9 @@ function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filt
12531253
element[0].checked = ctrl.$viewValue;
12541254
};
12551255

1256-
// Override the standard `$isEmpty` because a value of `false` means empty in a checkbox.
1256+
// Override the standard `$isEmpty` because an empty checkbox is always set to `false`
12571257
ctrl.$isEmpty = function(value) {
1258-
return value !== trueValue;
1258+
return value === false;
12591259
};
12601260

12611261
ctrl.$formatters.push(function(value) {

test/ng/directive/inputSpec.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -3623,7 +3623,7 @@ describe('input', function() {
36233623

36243624

36253625
it('should be required if false', function() {
3626-
compileInput('<input type="checkbox" ng:model="value" required />');
3626+
compileInput('<input type="checkbox" ng-model="value" required />');
36273627

36283628
browserTrigger(inputElm, 'click');
36293629
expect(inputElm[0].checked).toBe(true);
@@ -3633,6 +3633,16 @@ describe('input', function() {
36333633
expect(inputElm[0].checked).toBe(false);
36343634
expect(inputElm).toBeInvalid();
36353635
});
3636+
3637+
it('should not be required with ngTrueValue', function() {
3638+
compileInput('<input type="checkbox" ng-model="value" required ng-true-value="\'yes\'" />');
3639+
3640+
expect(inputElm).toBeInvalid();
3641+
3642+
browserTrigger(inputElm, 'click');
3643+
expect(inputElm[0].checked).toBe(true);
3644+
expect(inputElm).toBeValid();
3645+
});
36363646
});
36373647

36383648

0 commit comments

Comments
 (0)