Skip to content

Commit

Permalink
Include persistent parameters in search query
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Apr 25, 2023
1 parent d38837b commit 9ee77c1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion assets/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function initFormControls()
if (this.classList.contains('ajax') || this.dataset['ajax-Url'] !== undefined) {
options.minimumResultsForSearch = 0;
options.ajax = {delay: 250, cache: true, transport: (request, done, error) => {
let params = {};
let params = findPrefixedUrlParams(formName);
params[formName+'-term'] = request.data.term || '';
params[formName+'-page'] = request.data.page || 1;

Expand Down Expand Up @@ -60,6 +60,24 @@ function initFormControls()
}


function findPrefixedUrlParams(prefix)
{
let url = new URL(document.location);
let urlSearch = new URLSearchParams(url.search);
let params = {};

for (let key of urlSearch.keys()) {
if (!key.startsWith(prefix)) {
continue;
}

params[key] = urlSearch.get(key);
}

return params;
}


/**
* @see https://stackoverflow.com/a/11077016
*/
Expand Down

0 comments on commit 9ee77c1

Please sign in to comment.