correct issue with modal tag management submit function.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user