-Suppose I have 2 dropdown fields…
When an item from the first dropdown is selected it triggers DetailsSelection (see below) which is a function that runs a query with some filters and then populates the second dropdown based on the selection of the first dropdown, It also places a default property for .value() if a user selection had already been made previously and the user decided to go back and change the value of the first dropdown
The selection of the second dropdown triggers a chain of other elements to perform specific actions (show a certain image, show a set of specific buttons for the selection, show descriptive text)
LookBack is a function that only executes in the event that both dropdowns had values previously selected, but the user decided to change the first again. That would trigger the DetailsSelectiin to repopulate the second dropdown and assign the default value.
It’s supposed to read the new value of the second dropdown and reconfigure the next level element actions as described above.
export async function styledropdown_change(event) {
await
DetailsSelection();
LookBack();
}
The issue is that before the new value of the second dropdown populates, the LookBack function finishes execution and falsely determines no change in that dropdown. I imagined that the function above would await DetailsSelection to finish before executing LookBack, but after many console.log tests, it’s never the case. I suspect that it’s only awaiting the callback of the function and not necessarily the function itself.
I’m currently using the workaround below but it’s not as elegant as I would prefer, plus I fear that it may be subject to issues in case of system lag or something like it.
export function styledropdown_change(event) {
DetailsSelection();
setTimeout(function() {
LookBack();
}, 2000);
}
Can anyone think of a proper fix for the async function?