Move reset button initialization logic to initFormElements()

This commit is contained in:
Jeremy Stretch 2024-08-27 10:25:29 -04:00
parent 6a251fbad9
commit 63638bf874
4 changed files with 8 additions and 18 deletions

Binary file not shown.

Binary file not shown.

View File

@ -39,10 +39,17 @@ export function initFormElements(): void {
// Find each of the form's submitters. Most object edit forms have a "Create" and
// a "Create & Add", so we need to add a listener to both.
const submitters = form.querySelectorAll<HTMLButtonElement>('button[type=submit]');
for (const submitter of submitters) {
// Add the event listener to each submitter.
submitter.addEventListener('click', (event: Event) => handleFormSubmit(event, form));
}
// Initialize any reset buttons so that when clicked, the page is reloaded without query parameters.
const resetButton = document.querySelector<HTMLButtonElement>('button[data-reset-select]');
if (resetButton !== null) {
resetButton.addEventListener('click', () => {
window.location.assign(window.location.origin + window.location.pathname);
});
}
}
}

View File

@ -68,9 +68,6 @@ export class DynamicTomSelect extends TomSelect {
this.updatePathValues(filter);
}
// Initialize controlling elements.
this.initResetButton();
// Add dependency event listeners.
this.addEventListeners();
}
@ -314,20 +311,6 @@ export class DynamicTomSelect extends TomSelect {
}
}
/**
* Initialize any adjacent reset buttons so that when clicked, the page is reloaded without
* query parameters.
*/
private initResetButton(): void {
const resetButton = document.querySelector<HTMLButtonElement>('button[data-reset-select]');
if (resetButton !== null) {
resetButton.addEventListener('click', () => {
window.location.assign(window.location.origin + window.location.pathname);
});
}
}
/**
* Events
*/