From a69ed2677a0cb952d167376dd09826822bfd6a04 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 May 2023 21:21:31 +0200 Subject: [PATCH] Searchbar js code --- core/templates/base.html | 5 +++++ static/dist/js/searchsuggestions.js | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/templates/base.html b/core/templates/base.html index 1e0b380..421d8e5 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -51,6 +51,7 @@
+
+
+
diff --git a/static/dist/js/searchsuggestions.js b/static/dist/js/searchsuggestions.js index 5db7484..04035dd 100644 --- a/static/dist/js/searchsuggestions.js +++ b/static/dist/js/searchsuggestions.js @@ -1,13 +1,27 @@ +/* const searchinput = document.querySelector("#searchinput"); +const searchsuggestions = document.querySelector("#searchsuggestions"); searchinput.addEventListener("input", (e) => { q(e.target.value); }); async function q(s) { try { - const response = await fetch("http://localhost:8000/api/?q=" + s); + const response = await fetch("/api/?q=" + s); const result = await response.json(); console.log("Success: " + JSON.stringify(result)); + setSuggestions(searchsuggestions, result); } catch(error) { console.log("Error: " + error); } -} \ No newline at end of file +} +function setSuggestions(o, s) { + const newSuggestions = []; + for (const vid of s) { + const newSugg = document.createElement("a"); + newSugg.setAttribute("href", "/view/" + vid.id); + newSugg.insertAdjacentText("afterbegin", vid.name + " " + vid.id); + newSuggestions.push(newSugg); + } + o.replaceChildren(...newSuggestions); +} +*/