Skip to content

Commit

Permalink
Move clearing results to after fetch is complete
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed May 16, 2023
1 parent 25f28fa commit 9bee3b1
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions core/src/main/resources/lib/form/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ function updateListBox(listBox, url, config) {
status.innerHTML = "";
}
config.onSuccess = function (rsp) {
l.classList.remove("select-ajax-pending");
var currentSelection = l.value;
rsp.json().then((result) => {
l.classList.remove("select-ajax-pending");
var currentSelection = l.value;

// clear the contents
while (l.length > 0) {
l.options[0] = null;
}
// clear the contents
while (l.length > 0) {
l.options[0] = null;
}

var selectionSet = false; // is the selection forced by the server?
var possibleIndex = null; // if there's a new option that matches the current value, remember its index

var selectionSet = false; // is the selection forced by the server?
var possibleIndex = null; // if there's a new option that matches the current value, remember its index
rsp.json().then((result) => {
var opts = result.values;
for (var i = 0; i < opts.length; i++) {
l.options[i] = new Option(opts[i].name, opts[i].value);
Expand All @@ -77,8 +78,8 @@ function updateListBox(listBox, url, config) {
});
};
config.onFailure = function (rsp) {
l.classList.remove("select-ajax-pending");
rsp.text().then((responseText) => {
l.classList.remove("select-ajax-pending");
status.innerHTML = responseText;
if (status.firstElementChild) {
status.firstElementChild.setAttribute("data-select-ajax-error", "true");
Expand Down

0 comments on commit 9bee3b1

Please sign in to comment.