Searchbar fix 1

This commit is contained in:
Vivek Teega 2020-06-24 10:51:45 +05:30
parent 72ead02bb3
commit 07481c7fa6

View File

@ -547,7 +547,7 @@
winningChoice, winningChoice,
committeeAddress committeeAddress
} = obj, } = obj,
card = document.createElement("div"); card = document.createElement("div");
card.classList.add("transaction", "contract-trigger"); card.classList.add("transaction", "contract-trigger");
card.id = hash; card.id = hash;
card.innerHTML = ` <svg class="icon" viewBox="0 0 64 64"> card.innerHTML = ` <svg class="icon" viewBox="0 0 64 64">
@ -834,11 +834,16 @@
} }
window.addEventListener("load", async () => { window.addEventListener("load", async () => {
document.getElementById("main_search_field").addEventListener("keydown", function (e) { document.getElementById("main_search_field").addEventListener("keydown", function (e) {
if (e.key === 'Enter') { if (e.key === 'Enter') {
processNavbarSearch(); processNavbarSearch()
hidePage('search_page')
e.target.value = ''
} }
}); });
let themeToggler = document.getElementById("theme_toggle"), let themeToggler = document.getElementById("theme_toggle"),
body = document.querySelector("body"); body = document.querySelector("body");
if (localStorage.theme === "dark") { if (localStorage.theme === "dark") {
@ -1765,6 +1770,12 @@
index.add(i, data[i]); index.add(i, data[i]);
} }
var suggestions = document.getElementById("suggestions");
var autocomplete = document.getElementById("autocomplete");
var userinput = document.getElementById("main_search_field");
suggestions.addEventListener("click", accept_suggestion, true);
window.suggestion = function (str) { window.suggestion = function (str) {
let li = document.createElement('li') let li = document.createElement('li')
li.textContent = str li.textContent = str
@ -1773,6 +1784,17 @@
return li; return li;
} }
function accept_suggestion(event) {
var target = (event || window.event).target;
userinput.value = autocomplete.value = target.textContent;
while (suggestions.lastChild) {
suggestions.removeChild(suggestions.lastChild);
}
return false;
}
} }
</script> </script>