Commit 9e8f0e63 authored by Clement Ho's avatar Clement Ho

Load searched params into input field

parent cf8ae790
......@@ -23,6 +23,7 @@
class FilteredSearchManager {
constructor() {
this.bindEvents();
this.loadSearchParamsFromURL();
this.clearTokens();
}
......@@ -38,6 +39,31 @@
this.searchToken = '';
}
loadSearchParamsFromURL() {
const params = window.location.search.split('&');
let inputValue = '';
params.forEach((p) => {
const split = p.split('=');
const key = split[0];
const value = split[1];
const match = validTokenKeys.find((t) => {
return key === `${t.key}_${t.param}`;
});
if (match) {
const sanitizedKey = key.slice(0, key.indexOf('_'));
inputValue += `${sanitizedKey}:${value} `;
} else if (!match && key === 'search') {
inputValue += `${value} `;
}
});
// Trim the last space value
document.querySelector('.filtered-search').value = inputValue.trim();
}
tokenize(event) {
// Re-calculate tokens
this.clearTokens();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment