-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_groupe.js
executable file
·73 lines (58 loc) · 2.66 KB
/
script_groupe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
document.addEventListener('DOMContentLoaded', () => {
const dropdownBtn = document.querySelector('.dropdown-btn');
const dropdownContent = document.querySelector('.dropdown-content');
dropdownBtn.addEventListener('click', () => {
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', (event) => {
if (!dropdownBtn.contains(event.target) && !dropdownContent.contains(event.target)) {
dropdownContent.style.display = 'none';
}
});
});
document.addEventListener("DOMContentLoaded", function () {
document.getElementById('ajouterEleveBtn').addEventListener('click', function () {
const checkboxes = document.querySelectorAll('.etudiant-checkbox:checked');
const listePrevisu = document.getElementById('listePrevisu');
const formGroupe = document.getElementById('formGroupe');
if (checkboxes.length === 0) {
listePrevisu.innerHTML = "<p style='color:red;'>Aucun étudiant sélectionné.</p>";
return;
}
listePrevisu.innerHTML = '';
document.querySelectorAll('input[name="etudiants[]"]').forEach(input => input.remove());
checkboxes.forEach(function (checkbox) {
const nom = checkbox.dataset.nom;
const prenom = checkbox.dataset.prenom;
const id = checkbox.value;
const p = document.createElement('p');
p.className = 'eleve';
p.textContent = `${nom} ${prenom} (ID: ${id})`;
listePrevisu.appendChild(p);
const inputHidden = document.createElement('input');
inputHidden.type = 'hidden';
inputHidden.name = 'etudiants[]';
inputHidden.value = id;
formGroupe.appendChild(inputHidden);
});
});
});
document.querySelector('.custom-dropdown .dropdown-btn').addEventListener('click', function() {
const dropdown = this.closest('.custom-dropdown');
dropdown.classList.toggle('open');
});
document.addEventListener("DOMContentLoaded", function() {
const checkboxes = document.querySelectorAll(".etudiant-checkbox");
const hiddenInput = document.getElementById("etudiants_selectionnes");
checkboxes.forEach(checkbox => {
checkbox.addEventListener("change", function() {
let selectedIds = [];
checkboxes.forEach(box => {
if (box.checked) {
selectedIds.push(box.value);
}
});
hiddenInput.value = selectedIds.join(",");
});
});
});