-
Hier ist eine erweiterte Version, in der die Eingabefelder so gruppiert werden, dass das Ergebnis pro Gruppe nur einmal eingetragen werden muss:
console.info("Sorted table and added tab support."); //Suchen der Tabellenzeile, in der der Name der Gruppe steht let table = document.querySelector(".flexible.generaltable.generalbox>tbody"); let col = [...table.previousSibling.firstChild.childNodes].findIndex(a=>a.textContent==="Gruppe"); //Bildet eine Tabellenzeile auf ihre Gruppennummer ab let map = a=>+[...a.childNodes[col].textContent.matchAll(/\d+/g)].pop(); //Sortieren der Tabellenzeilen let rows = [...table.childNodes]; rows.sort((a,b)=>map(a)>map(b)?1:-1).forEach((s)=>table.append(s)); //Gruppieren der Eingabefelder let lastGroup; let groupedInputs; for(let row of rows){ let group = row.childNodes[col].textContent; let input = row.querySelector("input.quickgrade"); if(group != lastGroup){ groupedInputs = [input]; input.tabIndex = 1; lastGroup = group; }else{ groupedInputs.push(input); row.tabIndex = 0; input.addEventListener("focus", function(){ this.tabIndex = 1; }); input.addEventListener("blur", function(){ this.tabIndex = 0; }); } input.addEventListener("change", function(){ for(let i of this.groupedInputs){ if(this===i) continue; i.value = this.value; i.parentElement.classList.add("quickgrademodified") } }); input.groupedInputs = groupedInputs; } document.querySelector("#id_savequickgrades").tabIndex = 1;
Please register or sign in to comment