Update web/templates/search.html
This commit is contained in:
+14
-13
@@ -401,33 +401,34 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- Save q + selected fields at the moment the search form submits -->
|
<!-- Save q + selected fields exactly as submitted -->
|
||||||
<script>
|
<script>
|
||||||
(function(){
|
(function(){
|
||||||
const form = document.querySelector('form.search-form');
|
const form = document.querySelector('form.search-form') || document.querySelector('form[method="get"]');
|
||||||
if (!form) return;
|
if (!form) return;
|
||||||
|
|
||||||
const qInput = form.querySelector('input[name="q"]');
|
const qInput = form.querySelector('input[name="q"]');
|
||||||
|
|
||||||
function getSelectedFields(scope=form){
|
|
||||||
const out = [];
|
|
||||||
scope.querySelectorAll('input[type="checkbox"][name^="sel["]').forEach(cb => {
|
|
||||||
if (cb.checked) out.push(cb.name.slice(4, -1)); // sel[illustration] -> illustration
|
|
||||||
});
|
|
||||||
return out.length ? out : ["subject"]; // backend default
|
|
||||||
}
|
|
||||||
|
|
||||||
form.addEventListener('submit', () => {
|
form.addEventListener('submit', () => {
|
||||||
|
const fd = new FormData(form);
|
||||||
|
const fields = [];
|
||||||
|
for (const [k, v] of fd.entries()) {
|
||||||
|
// sel[field]=on → capture "field"
|
||||||
|
if (k.startsWith('sel[') && k.endsWith(']') && (v === 'on' || v === 'true' || v === '1')) {
|
||||||
|
fields.push(k.slice(4, -1));
|
||||||
|
}
|
||||||
|
}
|
||||||
const q = (qInput && qInput.value || '').trim();
|
const q = (qInput && qInput.value || '').trim();
|
||||||
const fields = getSelectedFields();
|
|
||||||
|
// Store exactly what the user selected — NO default to ["subject"]
|
||||||
try {
|
try {
|
||||||
localStorage.setItem('lastSearchQ', q);
|
localStorage.setItem('lastSearchQ', q);
|
||||||
localStorage.setItem('lastSearchFields', JSON.stringify(fields));
|
localStorage.setItem('lastSearchFields', JSON.stringify(fields));
|
||||||
} catch(_) {}
|
} catch (_) {}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user