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) {
|
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user