Update web/templates/search.html

This commit is contained in:
Joshua Laymon 2025-08-24 00:28:53 +00:00
parent e3ea0e2028
commit c64e8d0b30

View File

@ -401,33 +401,34 @@
}
</style>
<!-- Save q + selected fields at the moment the search form submits -->
<!-- Save q + selected fields exactly as submitted -->
<script>
(function(){
const form = document.querySelector('form.search-form');
const form = document.querySelector('form.search-form') || document.querySelector('form[method="get"]');
if (!form) return;
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', () => {
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 fields = getSelectedFields();
// Store exactly what the user selected — NO default to ["subject"]
try {
localStorage.setItem('lastSearchQ', q);
localStorage.setItem('lastSearchFields', JSON.stringify(fields));
} catch(_) {}
} catch (_) {}
});
})();
</script>
{% endblock %}