static: fix search redirecting entire page

This commit is contained in:
Jens Langhammer 2020-11-21 21:22:25 +01:00
parent f3010726d6
commit 4bd433d69e
4 changed files with 14 additions and 12 deletions
passbook/static/static

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,12 +1,3 @@
// Search clearing
document.querySelectorAll("input[type=search]").forEach((si) => {
si.addEventListener("search", (e) => {
if (si.value === "") {
si.parentElement.submit();
}
});
});
// Fetch from data-attributes
document.querySelectorAll("[data-pb-fetch-fill]").forEach((el) => {
const url = el.dataset.pbFetchFill;

View file

@ -82,6 +82,17 @@ export class AdminSiteShell extends LitElement {
this.loadContent();
});
});
// Make get forms (search bar) notify us on submit so we can change the hash
this.querySelectorAll("form").forEach((f) => {
f.addEventListener("submit", (e) => {
e.preventDefault();
const formData = new FormData(f);
const qs = new URLSearchParams(
<any>(<unknown>formData)
).toString();
window.location.hash = `#${url}?${qs}`;
});
});
setTimeout(() => {
this.loading = false;
}, 100);