fix(frontend): remove duplicate options from datalist and select

This commit is contained in:
Mariano Riefolo 2024-09-04 14:01:18 +02:00
parent 2df5352c1c
commit 73091f29ed

View File

@ -20,11 +20,12 @@ function load_teachers(id) {
.then((data) => {
sessionStorage.setItem("teachers", JSON.stringify(data));
let i = 0;
const list = document.getElementById("teachers");
list.innerHTML = "";
data.forEach((el) => {
const select = document.getElementById("teachers");
const option = document.createElement("option");
option.value = el;
select.appendChild(option);
list.appendChild(option);
i++;
});
});
@ -34,8 +35,14 @@ function load_classes(id) {
fetch(`/api/classi?id=${id}`)
.then((response) => response.json())
.then((data) => {
const select = document.getElementById("year");
for (let i = 0; i < select.children.length; i++) {
if (!select.children[i].hasAttribute("disabled")) {
select.removeChild(select.children[i]);
i--;
}
}
for (let i = 0; i < data.length; i++) {
const select = document.getElementById("year");
const option = document.createElement("option");
option.value = i;
option.text = i + 1;
@ -129,8 +136,14 @@ function select_type() {
function load_section() {
let data = JSON.parse(sessionStorage.getItem("classes"));
let year = document.getElementById("year").value;
const select = document.getElementById("section");
for (let i = 0; i < select.children.length; i++) {
if (!select.children[i].hasAttribute("disabled")) {
select.removeChild(select.children[i]);
i--;
}
}
Object.keys(data[year]).forEach((el) => {
const select = document.getElementById("section");
const option = document.createElement("option");
option.value = el;
option.text = el;
@ -142,8 +155,14 @@ function load_major() {
let data = JSON.parse(sessionStorage.getItem("classes"));
let year = document.getElementById("year").value;
let section = document.getElementById("section").value;
let select = document.getElementById("major");
for (let i = 0; i < select.children.length; i++) {
if (!select.children[i].hasAttribute("disabled")) {
select.removeChild(select.children[i]);
i--;
}
}
data[year][section].forEach((el) => {
const select = document.getElementById("major");
const option = document.createElement("option");
option.value = el;
option.text = el;