var RGroup = (function () {
function RGroup() {
this.group = document.querySelectorAll('input[type="radio"]');
var _that = this;
[].map.call(this.group, function (_el) {
_el.addEventListener('change', _el['_change'] = function (ev) {
if (this.checked) {
this.hasCheck = true;
_that.leaveAll(this);
}
});
_el.addEventListener('click', _el['_click'] = function (ev) {
if (this.hasCheck) {
this.setAttribute('disabled', 'disabled');
_that.group.item(0).checked = true;
}
});
});
}
RGroup.prototype.leaveAll = function (current) {
[].map.call(this.group, function (_el) {
if (_el != current && _el.hasCheck) {
_el.hasCheck = false;
}
});
};
return RGroup;
}());
var rg = new RGroup();
ну, или посовременней
spoilerclass RGroup {
constructor() {
this.group = document.querySelectorAll('input[type="radio"]');
let _that = this;
[].map.call(this.group, function (_el) {
_el.addEventListener('change', _el['_change'] = function (ev) {
if (this.checked) {
this.hasCheck = true;
_that.leaveAll(this);
}
});
_el.addEventListener('click', _el['_click'] = function (ev) {
if (this.hasCheck) {
this.setAttribute('disabled', 'disabled');
_that.group.item(0).checked = true;
}
});
});
}
leaveAll(current) {
[].map.call(this.group, function (_el) {
if (_el != current && _el.hasCheck) {
_el.hasCheck = false;
}
});
}
}
let rg = new RGroup();