Skip to content

Commit 72a4275

Browse files
Narretzpetebacondarwin
authored andcommitted
fix(input[radio]): use non-strict comparison for checkedness
This was introduced during the switch to ESLint (b1bc251#diff-c244afd8def7f268b16ee91a0341c4b2R1691), but it is a breaking change. In master, we made an exception for this comparison when we introduced jshint eqeqeq (which was not backported to 1.5.x). PR (angular#15289)
1 parent befb190 commit 72a4275

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ng/directive/input.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,9 @@ function radioInputType(scope, element, attr, ctrl) {
17531753

17541754
ctrl.$render = function() {
17551755
var value = attr.value;
1756-
element[0].checked = (value === ctrl.$viewValue);
1756+
// We generally use strict comparison. This is behavior we cannot change without a BC.
1757+
// eslint-disable-next-line eqeqeq
1758+
element[0].checked = (value == ctrl.$viewValue);
17571759
};
17581760

17591761
attr.$observe('value', ctrl.$render);

test/ng/directive/inputSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -3871,6 +3871,17 @@ describe('input', function() {
38713871
});
38723872

38733873

3874+
it('should use non-strict comparison between model and value', function() {
3875+
$rootScope.selected = false;
3876+
var inputElm = helper.compileInput('<input type="radio" ng-model="selected" ng-value="false">' +
3877+
'<input type="radio" ng-model="selected" ng-value="\'\'">' +
3878+
'<input type="radio" ng-model="selected" ng-value="0">');
3879+
3880+
expect(inputElm[0].checked).toBe(true);
3881+
expect(inputElm[1].checked).toBe(true);
3882+
expect(inputElm[2].checked).toBe(true);
3883+
});
3884+
38743885
it('should watch the expression', function() {
38753886
var inputElm = helper.compileInput('<input type="radio" ng-model="selected" ng-value="value">');
38763887

0 commit comments

Comments
 (0)