Skip to content

Commit

Permalink
Add refillOnChange support
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Oct 13, 2024
1 parent cf7ff5e commit 4342e5b
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/main/js/components/combo-box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,37 @@ function init() {
behaviorShim.specify("INPUT.combobox2", "combobox", 100, function (e) {
// form field with auto-completion support
// insert the auto-completion container
const div = document.createElement("DIV");
e.parentNode.insertBefore(div, e.nextElementSibling);
e.style.position = "relative";
refillOnChange(e, function (params) {
const div = document.createElement("DIV");
e.parentNode.insertBefore(div, e.nextElementSibling);
e.style.position = "relative";

const url = e.getAttribute("fillUrl");
fetch(url)
.then((rsp) => (rsp.ok ? rsp.json() : {}))
.then((items) => {
e.addEventListener("focus", () => updateSuggestions(e, div, items));
const url = e.getAttribute("fillUrl");
fetch(url, {
headers: crumb.wrap({
"Content-Type": "application/x-www-form-urlencoded",
}),
method: "post",
body: new URLSearchParams(params),
})
.then((rsp) => (rsp.ok ? rsp.json() : {}))
.then((items) => {
e.addEventListener("focus", () => updateSuggestions(e, div, items));

// otherwise menu won't hide on tab with nothing selected
// needs delay as without that it blocks click selection of an item
e.addEventListener("focusout", () =>
setTimeout(() => e.dropdown.hide(), 200),
);
// otherwise menu won't hide on tab with nothing selected
// needs delay as without that it blocks click selection of an item
e.addEventListener("focusout", () =>
setTimeout(() => e.dropdown.hide(), 200),
);

e.addEventListener(
"input",
debounce(() => {
updateSuggestions(e, div, items);
}),
);
});
e.addEventListener(
"input",
debounce(() => {
updateSuggestions(e, div, items);
}),
);
});
});
});
}

Expand Down

0 comments on commit 4342e5b

Please sign in to comment.