Trying to create a bootstrap 5 popover with dynamic content by using an asynchronous function has been quite a challenge. Here is how I am setting up my popover:
document.querySelectorAll('[data-bs-toggle="popover"]').forEach(function (popover) {
new bootstrap.Popover(popover, {
content: function () {
(async () => {
var x = await PopulatePopoverContent();
return x;
})()
}
});
});
The next step involves fetching data from the database within the function SetPopoverContent():
async function SetPopoverContent(popOver) {
let contentText = '';
let data = await dotNetReference.invokeMethodAsync('GetChatToInfo', messageId);
if (data != null && data != undefined) {
var outerDiv = '<div></div>';
...
contentText = outerDiv.innerHTML;
}
else {
contentText = '<p>Loading</p>';
}
return contentText;
}
Although I can observe the HTML string within the popover content function, unfortunately, the content does not display in the popover itself. Could it be due to an error in the async callback method?