From a4ce9b5ad43f23431182b34b2ed36c687e81d982 Mon Sep 17 00:00:00 2001 From: ffont Date: Wed, 10 Apr 2024 13:55:53 +0200 Subject: [PATCH] Properly bind form submit on cluster select --- .../src/components/asyncSection.js | 3 +++ .../static/bw-frontend/src/pages/search.js | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/freesound/static/bw-frontend/src/components/asyncSection.js b/freesound/static/bw-frontend/src/components/asyncSection.js index 7cdf54a16..4cdc18151 100644 --- a/freesound/static/bw-frontend/src/components/asyncSection.js +++ b/freesound/static/bw-frontend/src/components/asyncSection.js @@ -12,6 +12,9 @@ const prepareAsyncSections = (container) => { element.innerHTML = req.responseText; // Make sure we initialize sound/pack players inside the async section initializeStuffInContainer(element, true, false); + + // Also trigger event to notify that async section has been loaded (this is currently used in search page to perform some actions) + document.dispatchEvent(new Event('async_section_loaded')); } else { // Unexpected errors happened while processing request: show toast showToast('Unexpected errors occurred while loading some of the content of this page. Please try again later...') diff --git a/freesound/static/bw-frontend/src/pages/search.js b/freesound/static/bw-frontend/src/pages/search.js index cb2cb3756..0c9290e82 100644 --- a/freesound/static/bw-frontend/src/pages/search.js +++ b/freesound/static/bw-frontend/src/pages/search.js @@ -176,14 +176,19 @@ if (sortByElement !== null){ }) } -// Make radio cluster elements submit the form when changed -document.getElementsByName('cid').forEach(radio => { - radio.addEventListener('change', (evt) => { - setTimeout(() => { - searchFormElement.submit(); - }, 100); // Give it a little time to update the radio widget before submitting - }); -}) +// Make radio cluster elements submit the form when changed (also when cluster section is loaded asynchronously) +export const bindClusteringRadioButtonsSubmit = () => { + document.getElementsByName('cid').forEach(radio => { + radio.addEventListener('change', (evt) => { + setTimeout(() => { + searchFormElement.submit(); + }, 100); // Give it a little time to update the radio widget before submitting + }); + }) +} +bindClusteringRadioButtonsSubmit(); +document.addEventListener('async_section_loaded', () => bindClusteringRadioButtonsSubmit()); + document.body.addEventListener('keydown', evt => { const ENTER_KEY = 13