Currently in my NodeJS app I have an inline confirmation to delete a record:
<form id="btn-form" action="/thought/<%- thought._id %>?_method=DELETE" method="POST" onclick="return confirm('Are you sure you wish to delete this thought post?');">
<button ><i ></i></button>
</form>
I would like to use Sweet Alert2 for the 'are you sure' popup message; so far I have this, though I'm unsure how to translate the inline method DELETE/POST to the Sweet Alert result.isConfirmed function
<form id="btn-form" action="/thought/<%- thought._id %>?_method=DELETE" method="POST" onclick="ConfirmDelete()">
<button ><i ></i></button>
</form>
function ConfirmDelete() {
return confirm('Are you sure you wish to delete this record?');
Swal.fire({
title: 'Are you sure you wish to delete this record?',
showDenyButton: true,
showCancelButton: true,
confirmButtonText: 'Yes',
denyButtonText: 'No',
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
Swal.fire('Record deleted!', '', 'success')
} else if (result.isDenied) {
Swal.fire('Record not deleted', '', 'info')
}
})
}
CodePudding user response:
You can call javascript fetch
inside the sweetalert if user confirmed
fetch(`URL`, {method: "DELETE",})