Searchbar js code
This commit is contained in:
parent
21ee170302
commit
a69ed2677a
|
|
@ -51,6 +51,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
<div class="float-right" style="width:100%">
|
||||
|
||||
<form class="form-inline ml-0 ml-md-3 float-right">
|
||||
<div class="input-group input-group-sm">
|
||||
<input class="form-control form-control-navbar"
|
||||
|
|
@ -58,6 +59,9 @@
|
|||
placeholder="Search"
|
||||
aria-label="Search"
|
||||
id="searchinput">
|
||||
<!--
|
||||
<div id="searchsuggestions"></div>
|
||||
-->
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-navbar" type="submit">
|
||||
<i class="fas fa-search"></i>
|
||||
|
|
@ -65,6 +69,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
18
static/dist/js/searchsuggestions.js
vendored
18
static/dist/js/searchsuggestions.js
vendored
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user