Skip to content

Commit e966922

Browse files
authored
Merge pull request #1066 from drgrice1/bugfix/radio-uncheckable
Fix an issue with uncheckable radio buttons.
2 parents 8938305 + 0fab5bf commit e966922

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

htdocs/js/RadioButtons/RadioButtons.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@
1515
'use strict';
1616

1717
(() => {
18+
const radioGroups = {};
19+
1820
// Setup uncheckable radios.
1921
const setupUncheckableRadio = (radio) => {
2022
if (!radio.dataset.uncheckableRadioButton) return;
2123
delete radio.dataset.uncheckableRadioButton;
2224

25+
if (!radioGroups[radio.name]) radioGroups[radio.name] = [radio];
26+
else radioGroups[radio.name].push(radio);
27+
2328
if (radio.checked) radio.dataset.currentlyChecked = '1';
2429

2530
radio.addEventListener('click', (e) => {
31+
for (const groupRadio of radioGroups[radio.name]) {
32+
if (groupRadio === radio) continue;
33+
delete groupRadio.dataset.currentlyChecked;
34+
}
2635
if (radio.dataset.shift && !e.shiftKey) {
2736
radio.dataset.currentlyChecked = '1';
2837
return;
2938
}
30-
const currentlyChecked = radio.dataset.currentlyChecked;
31-
if (currentlyChecked) {
39+
if (radio.dataset.currentlyChecked) {
3240
delete radio.dataset.currentlyChecked;
3341
radio.checked = false;
3442
} else {

0 commit comments

Comments
 (0)