MediaWiki:CRT Search.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 224: | Line 224: | ||
container.innerHTML = buildHTML(); | container.innerHTML = buildHTML(); | ||
attachEventListeners(); | attachEventListeners(); | ||
// Load filter options, then parse URL params, then perform initial search | |||
// URL params must be parsed AFTER filter options are loaded so that | |||
// select dropdowns have their options populated before we try to set values | |||
loadFilterOptions(); | loadFilterOptions(); | ||
} | } | ||
| Line 587: | Line 588: | ||
Promise.all(promises).then(function() { | Promise.all(promises).then(function() { | ||
// First populate the select dropdowns with their options | |||
populateSelectFilters(); | populateSelectFilters(); | ||
// Then parse URL params - this must happen AFTER options are loaded | |||
// so that select values can be properly set | |||
parseURLParams(); | |||
// Finally perform the initial search with any URL-specified filters | |||
performSearch(); | performSearch(); | ||
}); | }); | ||
| Line 949: | Line 957: | ||
} | } | ||
/** | /** | ||
* Perform search with subobject conditions (inputs/mods) | * Perform search with subobject conditions (inputs/mods) | ||
| Line 1,430: | Line 1,431: | ||
/** | /** | ||
* Parse URL parameters and set filters | * Parse URL parameters and set filters | ||
* This must be called AFTER filter options are loaded so that | |||
* select dropdowns have their options available | |||
*/ | */ | ||
function parseURLParams() { | function parseURLParams() { | ||
var params = new URLSearchParams(window.location.search); | var params = new URLSearchParams(window.location.search); | ||
// No URL params to process | |||
if (params.toString() === '') { | |||
return; | |||
} | |||
params.forEach(function(value, key) { | params.forEach(function(value, key) { | ||
| Line 1,444: | Line 1,452: | ||
} | } | ||
// Find the filter | // Find the filter config | ||
var filterConfig = null; | var filterConfig = null; | ||
for (var sectionKey in FILTER_CONFIG) { | for (var sectionKey in FILTER_CONFIG) { | ||
| Line 1,457: | Line 1,465: | ||
switch (filterConfig.type) { | switch (filterConfig.type) { | ||
case 'select': | case 'select': | ||
var select = document.getElementById('filter-' + key); | |||
if (select) { | |||
// Verify the option exists before setting | |||
var optionExists = Array.from(select.options).some(function(opt) { | |||
return opt.value === value; | |||
}); | |||
if (optionExists) { | |||
select.value = value; | |||
} else { | |||
console.warn('Filter option not found:', key, value); | |||
} | |||
} | |||
break; | |||
case 'number': | case 'number': | ||
var input = document.getElementById('filter-' + key); | var input = document.getElementById('filter-' + key); | ||
| Line 1,473: | Line 1,494: | ||
v = v.trim(); | v = v.trim(); | ||
if (!v) return; | if (!v) return; | ||
// Check if tag already exists to avoid duplicates | |||
var existingTag = selectedContainer.querySelector('[data-value="' + CSS.escape(v) + '"]'); | |||
if (existingTag) return; | |||
var tag = document.createElement('span'); | var tag = document.createElement('span'); | ||
tag.className = 'crt-multiselect-tag'; | tag.className = 'crt-multiselect-tag'; | ||