Skip to content

Commit d89b470

Browse files
committed
clicking outside create tag
1 parent 82084e2 commit d89b470

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

static/foundation/js/vendor/tagging.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export function setupTagging({
206206
// Show all suggestions if input is empty, or filtered if not
207207
const query = input.value.trim().toLowerCase();
208208
suggestionsBox.innerHTML = "";
209+
209210
// Filter as in your input event
210211
const filtered = autocompleteSource.filter(
211212
(tag) =>
@@ -320,6 +321,14 @@ export function setupTagging({
320321
}
321322
}
322323
});
324+
input.addEventListener("blur", () => {
325+
const value = input.value.trim();
326+
if (value !== "") {
327+
// Reuse Enter key handling
328+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter" }));
329+
}
330+
// input.style.display = "none";
331+
});
323332

324333
// Update hidden input and JSON
325334
function updateHidden() {
@@ -642,9 +651,11 @@ export function enableEditableTagsInTable() {
642651
// Hide input when empty and blurred
643652
if (!input.dataset.bound) {
644653
input.addEventListener("blur", () => {
645-
if (input.value.trim() === "") {
646-
input.style.display = "none";
654+
const value = input.value.trim();
655+
if (value !== "") {
656+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter" }));
647657
}
658+
input.style.display = "none";
648659
});
649660

650661
input.dataset.bound = "true"; // ✅ Prevent rebinding blur

0 commit comments

Comments
 (0)