From b7b9f1f5799d162661386ec6f2b72bde9c3ae493 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 28 May 2026 15:49:46 +0200 Subject: cockpit: hide clear button when a student is selected --- cockpit/js/cockpit.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cockpit/js/cockpit.js b/cockpit/js/cockpit.js index 23714ab..f701706 100644 --- a/cockpit/js/cockpit.js +++ b/cockpit/js/cockpit.js @@ -45,6 +45,7 @@ async function initStudentSelection() { const sel = document.getElementById("student-selection"); const list = document.getElementById('student-selection-list'); const noResults = document.getElementById('student-selection-noresults'); + const clearBtn = document.getElementById('student-selection-clear'); const students = await fetchStudents(); @@ -99,21 +100,17 @@ async function initStudentSelection() { } } + // Show the clear button if there is an input + clearBtn.style.display = sel.value ? "block" : "none"; + // Select the first or none if there are no items visible currentFocus = visibleItems.length ? 0 : -1; setActive(visibleItems); noResults.style.display = visibleItems.length || filter === "" ? "none" : "block"; }); - const clearBtn = document.getElementById('student-selection-clear'); - - sel.addEventListener('input', function() { - clearBtn.style.display = sel.value ? "block" : "none"; - }); - clearBtn.addEventListener('click', function() { sel.value = ""; - clearBtn.style.display = "none"; sel.dispatchEvent(new Event('keyup')); // reset list sel.focus(); }); -- cgit v1.2.3