From 7a907f3c18a96215decdadd8c33e050aba28471e Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Fri, 22 Apr 2022 23:25:08 +0200 Subject: [PATCH] Prevent form submission and avoid sending empty queries --- search.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/search.md b/search.md index f436010..084f62f 100644 --- a/search.md +++ b/search.md @@ -63,6 +63,9 @@ function datefmt(ts) { return `${year}-${month}-${day}`; } +// Prevent form submission +document.querySelector("form").onsubmit = (e) => e.preventDefault(); + // Grab a reference to the const searchbox = document.getElementById("searchbox"); @@ -71,6 +74,8 @@ let requestInFlight = null; searchbox.onkeyup = debounce(() => { const q = searchbox.value; + if (!q) { return; } + // Construct the API URL, using encodeURIComponent() for the parameters const url = `https://fnordig.de/_search?search=${encodeURIComponent(q)}`; // Unique object used just for race-condition comparison