~netlandish/links

619094715895412c6e973b2aa8eb231de3b4b53c — Yader Velasquez 9 months ago 0b0bf23
Build query params dynamically in the advancedsearch.js

References: https://todo.code.netlandish.com/~netlandish/links/47
1 files changed, 13 insertions(+), 4 deletions(-)

M static/js/advancedsearch.js
M static/js/advancedsearch.js => static/js/advancedsearch.js +13 -4
@@ 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;
})