1
Fork 0

Prevent form submission and avoid sending empty queries

This commit is contained in:
Jan-Erik Rediger 2022-04-22 23:25:08 +02:00
parent 4fb0371fb4
commit 7a907f3c18

View file

@ -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 <input type="search">
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