From 4c56b73bc9c9c68cf74c4d209ad8db89ef994a76 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 18 Jan 2026 12:32:05 -0500 Subject: [PATCH] correct issue with modal tag management submit function. --- app/static/js/modal-pagination.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/static/js/modal-pagination.js b/app/static/js/modal-pagination.js index 317e4e8..8243d2c 100644 --- a/app/static/js/modal-pagination.js +++ b/app/static/js/modal-pagination.js @@ -159,6 +159,16 @@ document.addEventListener('DOMContentLoaded', () => { } } + // Shared function to submit a tag (avoids page refresh issues with form dispatch) + async function submitTag() { + const id = getEditorImageId(); + const name = (tagInput?.value || '').trim(); + if (!id || !name) return; + hideAutocomplete(); + await addTag(id, name); + if (tagInput) tagInput.value = ''; + } + if (tagInput) { // Show autocomplete on focus tagInput.addEventListener('focus', () => { @@ -196,8 +206,7 @@ document.addEventListener('DOMContentLoaded', () => { const selected = autocompleteItems[autocompleteSelectedIndex]; if (selected) { tagInput.value = selected.name; - hideAutocomplete(); - tagForm.dispatchEvent(new Event('submit')); + submitTag(); } } else if (e.key === 'Escape') { hideAutocomplete(); @@ -213,8 +222,7 @@ document.addEventListener('DOMContentLoaded', () => { const name = item.dataset.name; if (tagInput && name) { tagInput.value = name; - hideAutocomplete(); - tagForm.dispatchEvent(new Event('submit')); + submitTag(); } }); } @@ -222,12 +230,7 @@ document.addEventListener('DOMContentLoaded', () => { if (tagForm) { tagForm.addEventListener('submit', async (e) => { e.preventDefault(); - const id = getEditorImageId(); - const name = (tagInput.value || '').trim(); - if (!id || !name) return; - hideAutocomplete(); - await addTag(id, name); - tagInput.value = ''; + await submitTag(); }); } if (tagList) {