diff --git a/assets/js/advanced-search.js b/assets/js/advanced-search.js index 09c42f9..4572437 100644 --- a/assets/js/advanced-search.js +++ b/assets/js/advanced-search.js @@ -61,25 +61,46 @@ function populateCurrentFilters() { const urlParams = new URLSearchParams(window.location.search); // Search text - if (urlParams.has('search')) { - document.getElementById('adv-search-text').value = urlParams.get('search'); - } + document.getElementById('adv-search-text').value = urlParams.get('search') || ''; // Status - if (urlParams.has('status')) { - const statuses = urlParams.get('status').split(','); - const statusSelect = document.getElementById('adv-status'); - Array.from(statusSelect.options).forEach(option => { - option.selected = statuses.includes(option.value); - }); - } + const statuses = urlParams.has('status') ? urlParams.get('status').split(',') : []; + const statusSelect = document.getElementById('adv-status'); + Array.from(statusSelect.options).forEach(option => { + option.selected = statuses.includes(option.value); + }); + + // Date ranges + document.getElementById('adv-created-from').value = urlParams.get('created_from') || ''; + document.getElementById('adv-created-to').value = urlParams.get('created_to') || ''; + document.getElementById('adv-updated-from').value = urlParams.get('updated_from') || ''; + document.getElementById('adv-updated-to').value = urlParams.get('updated_to') || ''; + + // Priority range + document.getElementById('adv-priority-min').value = urlParams.get('priority_min') || ''; + document.getElementById('adv-priority-max').value = urlParams.get('priority_max') || ''; + + // Users + document.getElementById('adv-created-by').value = urlParams.get('created_by') || ''; + document.getElementById('adv-assigned-to').value = urlParams.get('assigned_to') || ''; } // Perform advanced search function performAdvancedSearch(event) { event.preventDefault(); - const params = new URLSearchParams(); + // Start from the CURRENT URL's params, not a fresh set, so a filter this + // form doesn't represent (e.g. a category/type filter applied via a + // dashboard quick-filter pill or stats-widget click) isn't silently + // dropped on submit. Only the params this form actually controls are + // set/cleared below; everything else passes through untouched. + const params = new URLSearchParams(window.location.search); + const advParams = [ + 'search', 'created_from', 'created_to', 'updated_from', 'updated_to', + 'status', 'priority_min', 'priority_max', 'created_by', 'assigned_to', + ]; + advParams.forEach(key => params.delete(key)); + params.delete('page'); // filters changed — reset to page 1 // Search text const searchText = document.getElementById('adv-search-text').value.trim();