I am using HTMX and sweetalert to delete rows in a wishlist. I want to display an alert in cases of an error like probably the internet goes offline. It would be a great user-experience to let them know that the deletion failed. I can't handle it directly with Django since it is an HTMX error. I went through the docs and the error i a to handle is htmx:responseError. Every solution I saw online was about swapping but all I want to do is display an alert. Any idea on how to do that. Below is my code,
document.body.addEventListener('htmx:confirm', function(evt) {
if (evt.target.getAttribute('confirm-with-sweet-alert') === 'true') {
evt.preventDefault(); // Prevent the request from being sent immediately
Swal.fire({
title: 'Remove from Wishlist?',
text: 'This item will be removed from your wishlist',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#dc3545',
cancelButtonColor: '#6c757d',
confirmButtonText: 'Yes, remove it!'
}).then((result) => {
if (result.isConfirmed) {
console.log(result)
const row = evt.target.closest('tr'); // Get the closest table row
row.classList.add('fade-out'); // Add the fade-out class
evt.detail.issueRequest(); // Proceed with the HTMX request
}
});
}
});
</script>```