Fix add-form JS: name→sort-name sync and related-game disable
Two bugs in the add forms, both root-caused via the e2e harness: 1. add_game Name → Sort name never synced. syncSelectInputUntilChanged was scoped to "form", but the first <form> on every page is the navbar logout form — the add-form fields live in a later form, so the delegated listener never heard their events. Scope to "#add-form" (the add-form wrapper). Also switch the sync from the "change" event to "input" so Sort name mirrors Name live as you type, not only on blur. 2. add_purchase Related game not disabled when Type == Game. disableElementsWhenTrue set `.disabled` on #id_related_game, which is the SearchSelect wrapper <div> (a <div> ignores `disabled`). Target the inner [data-search-select-search] input instead, so the widget is actually disabled. Adds two e2e regression tests (live sync; type-game disables the related-game search input and re-enables it for other types). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+4
-3
@@ -52,11 +52,12 @@ function syncSelectInputUntilChanged(syncData: Array<{ source: string; target: s
|
||||
console.error(`The parent selector "${parentSelector}" is not valid.`);
|
||||
return;
|
||||
}
|
||||
// Set up a single change event listener on the document for handling all source changes
|
||||
parentElement.addEventListener("change", function (event) {
|
||||
// One delegated "input" listener handles every source. "input" (not "change")
|
||||
// makes the mirror live as the user types, instead of only on blur.
|
||||
parentElement.addEventListener("input", function (event) {
|
||||
// Loop through each sync configuration item
|
||||
syncData.forEach((syncItem: { source: string; target: string; source_value: string; target_value: string }) => {
|
||||
// Check if the change event target matches the source selector
|
||||
// Check if the event target matches the source selector
|
||||
if ((event.target as HTMLElement).matches(syncItem.source)) {
|
||||
if (!event.target) return;
|
||||
const sourceElement = event.target;
|
||||
|
||||
Reference in New Issue
Block a user