/** * Reset a search form to the filters the server applied. * * React only writes a select's defaultValue into the DOM on the first render, * so a plain form.reset() after a search returns every select to the value the * page opened with (for example "Todas"), while the URL keeps the chosen group. * Selects that declare data-applied are aligned first, so the reset keeps the * applied choice and the focus stays where the investor left it. */ export function resetToAppliedFilters(form: HTMLFormElement | null): void { if (!form) return; for (const select of Array.from(form.querySelectorAll("select"))) { const applied = select.getAttribute("data-applied"); if (applied === null) continue; for (const option of Array.from(select.options)) option.defaultSelected = option.value === applied; } form.reset(); }