Skip to content

Commit 38d8367

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 5fa27a8 commit 38d8367

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
@@ -1616,7 +1616,9 @@ function radioInputType(scope, element, attr, ctrl) {
16161616

16171617
ctrl.$render = function() {
16181618
var value = attr.value;
1619-
element[0].checked = (value === ctrl.$viewValue);
1619+
// We generally use strict comparison. This is behavior we cannot change without a BC.
1620+
// eslint-disable-next-line eqeqeq
1621+
element[0].checked = (value == ctrl.$viewValue);
16201622
};
16211623

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

test/ng/directive/inputSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -3259,6 +3259,17 @@ describe('input', function() {
32593259
});
32603260

32613261

3262+
it('should use non-strict comparison between model and value', function() {
3263+
$rootScope.selected = false;
3264+
var inputElm = helper.compileInput('<input type="radio" ng-model="selected" ng-value="false">' +
3265+
'<input type="radio" ng-model="selected" ng-value="\'\'">' +
3266+
'<input type="radio" ng-model="selected" ng-value="0">');
3267+
3268+
expect(inputElm[0].checked).toBe(true);
3269+
expect(inputElm[1].checked).toBe(true);
3270+
expect(inputElm[2].checked).toBe(true);
3271+
});
3272+
32623273
it('should watch the expression', function() {
32633274
var inputElm = helper.compileInput('<input type="radio" ng-model="selected" ng-value="value">');
32643275

0 commit comments

Comments
 (0)