JSFiddle - React, Tailwind, and code Playground
HTML
<div id="testForm">
<h2 class="orange">Workshops</h2>
<ul>
<li><input id="A1" type="checkbox"><label for="A1">Worshop 1 : <strong>8:30 - 20:20</strong></label></li>
<li><input id="A2" type="checkbox"><label for="A2">Worshop 2 : <strong>8:30 - 20:20</strong></label></li>
<li><input id="A3" type="checkbox"><label for="A3">Worshop n°3 : <strong>14:30 - 15:15</strong></label></li>
<li><input id="A4" type="checkbox"><label for="A4">Worshop n°4 : <strong>14:30 - 15:15</strong></label></li>
<li><input id="A5" type="checkbox"><label for="A5">Worshop n°5 : <strong>15:30 - 16:45</strong></label></li>
<li><input id="A6" type="checkbox"><label for="A6">Worshop n°6 : <strong>15:30 - 16:45</strong></label></li>
<li><input id="A7" type="checkbox"><label for="A7">Worshop n°7 : <strong>16:30 - 17:15</strong></label></li>
<li><input id="A8" type="checkbox"><label for="A8">Worshop n°8 : <strong>16:45 - 17:15</strong></label></li>
</ul>
</div>
JavaScript
'use strict';
// the first entry is the id of each checkboxes, the followings are the checkboxes which should be disabled if this checkbox is checked
var plage = [['A1', 'allCheckbox'], ['A2', 'allCheckbox'], ['A3', 'A4'], ['A4', 'A3'], ['A5', 'A6', 'A7'], ['A6', 'A5', 'A7'], ['A7', 'A5', 'A6', 'A8'], ['A8', 'A7']];
var inputs = document.querySelectorAll('#testForm input');
var checkboxes = document.querySelectorAll('#testForm input[type=checkbox]');
inputs.forEach(function (item) {
item.addEventListener('click', function () {
var checked = verifChecked();
var itemDisabled = [];
//On commence par tout décocher
inputs.forEach(function (input) {
input.disabled = false;
});
//If there is nothing to check, exit the function
if (checked.length === 0) {
return;
}
//For every checked items
checked.forEach(function (idChecked) {
// We look in the arrays
for (var i = 0; i < plage.length; i++) {
var plageID = plage[i][0];
//Quand on trouve la bonne plage
if (plageID === idChecked) {
//we get the ids in the array (expect the first one)
for (var j = 1; j < plage[i].length; j++) {
//we push them in a new array
itemDisabled.push(plage[i][j]);
}
}
}
});
//If a checkbox should disable all the others (with the keyword allCheckbox)
if (itemDisabled.includes('allCheckbox')) {
checkboxes.forEach(function (checkbox) {
checkbox.disabled = true;
checkbox.checked = false;
});
item.disabled = false;
item.checked = true;
} else { //Else we disable the inputs contained in the array itemDisabled
...