correct issue with modal tag management submit function.

This commit is contained in:
Bryan Van Deusen
2026-01-18 12:32:05 -05:00
parent 21168117c1
commit 4c56b73bc9
+13 -10
View File
@@ -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) { if (tagInput) {
// Show autocomplete on focus // Show autocomplete on focus
tagInput.addEventListener('focus', () => { tagInput.addEventListener('focus', () => {
@@ -196,8 +206,7 @@ document.addEventListener('DOMContentLoaded', () => {
const selected = autocompleteItems[autocompleteSelectedIndex]; const selected = autocompleteItems[autocompleteSelectedIndex];
if (selected) { if (selected) {
tagInput.value = selected.name; tagInput.value = selected.name;
hideAutocomplete(); submitTag();
tagForm.dispatchEvent(new Event('submit'));
} }
} else if (e.key === 'Escape') { } else if (e.key === 'Escape') {
hideAutocomplete(); hideAutocomplete();
@@ -213,8 +222,7 @@ document.addEventListener('DOMContentLoaded', () => {
const name = item.dataset.name; const name = item.dataset.name;
if (tagInput && name) { if (tagInput && name) {
tagInput.value = name; tagInput.value = name;
hideAutocomplete(); submitTag();
tagForm.dispatchEvent(new Event('submit'));
} }
}); });
} }
@@ -222,12 +230,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (tagForm) { if (tagForm) {
tagForm.addEventListener('submit', async (e) => { tagForm.addEventListener('submit', async (e) => {
e.preventDefault(); e.preventDefault();
const id = getEditorImageId(); await submitTag();
const name = (tagInput.value || '').trim();
if (!id || !name) return;
hideAutocomplete();
await addTag(id, name);
tagInput.value = '';
}); });
} }
if (tagList) { if (tagList) {