Skip to content

Commit

Permalink
Properly bind form submit on cluster select
Browse files Browse the repository at this point in the history
  • Loading branch information
ffont committed Apr 10, 2024
1 parent b7c0fd4 commit a4ce9b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions freesound/static/bw-frontend/src/components/asyncSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...')
Expand Down
21 changes: 13 additions & 8 deletions freesound/static/bw-frontend/src/pages/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4ce9b5

Please sign in to comment.