Skip to content

Commit

Permalink
Merge pull request openwebwork#1066 from drgrice1/bugfix/radio-unchec…
Browse files Browse the repository at this point in the history
…kable

Fix an issue with uncheckable radio buttons.
  • Loading branch information
Alex-Jordan authored Apr 26, 2024
2 parents 8938305 + 0fab5bf commit e966922
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions htdocs/js/RadioButtons/RadioButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@
'use strict';

(() => {
const radioGroups = {};

// Setup uncheckable radios.
const setupUncheckableRadio = (radio) => {
if (!radio.dataset.uncheckableRadioButton) return;
delete radio.dataset.uncheckableRadioButton;

if (!radioGroups[radio.name]) radioGroups[radio.name] = [radio];
else radioGroups[radio.name].push(radio);

if (radio.checked) radio.dataset.currentlyChecked = '1';

radio.addEventListener('click', (e) => {
for (const groupRadio of radioGroups[radio.name]) {
if (groupRadio === radio) continue;
delete groupRadio.dataset.currentlyChecked;
}
if (radio.dataset.shift && !e.shiftKey) {
radio.dataset.currentlyChecked = '1';
return;
}
const currentlyChecked = radio.dataset.currentlyChecked;
if (currentlyChecked) {
if (radio.dataset.currentlyChecked) {
delete radio.dataset.currentlyChecked;
radio.checked = false;
} else {
Expand Down

0 comments on commit e966922

Please sign in to comment.