From 619094715895412c6e973b2aa8eb231de3b4b53c Mon Sep 17 00:00:00 2001 From: Yader Velasquez Date: Wed, 14 Feb 2024 11:46:14 -0600 Subject: [PATCH] Build query params dynamically in the advancedsearch.js References: https://todo.code.netlandish.com/~netlandish/links/47 --- static/js/advancedsearch.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/static/js/advancedsearch.js b/static/js/advancedsearch.js index 28ab0e8..226aa90 100644 --- a/static/js/advancedsearch.js +++ b/static/js/advancedsearch.js @@ -73,7 +73,8 @@ form.addEventListener("submit", function(e) { e.preventDefault(); var tagValue = form.elements.tag.value; var excludeValue = form.elements.exclude.value; - var qValue = form.elements.q.value + var qValue = form.elements.q.value; + var qURL = new URLSearchParams(); if (tagValue === "") { form.elements.tag.disabled = true; @@ -83,7 +84,7 @@ form.addEventListener("submit", function(e) { if (tagValue.endsWith(",")) { tagValue = tagValue.slice(0, -1); } - form.elements.tag.value = tagValue; + qURL.set("tag", tagValue); } if (excludeValue === "") { @@ -94,13 +95,21 @@ form.addEventListener("submit", function(e) { if (excludeValue.endsWith(",")) { excludeValue = excludeValue.slice(0, -1); } - form.elements.exclude.value = excludeValue; + qURL.set("exclude", excludeValue); } if (qValue === "") { form.elements.q.disabled = true; + } else { + qURL.set("q", qValue); + } + + url = this.getAttribute("action"); + params = qURL.toString(); + if (params !== "") { + url += "?" + params; } - this.submit(); + document.location = url; }) -- 2.45.2