Skip to content

Instantly share code, notes, and snippets.

@brahbassim
Last active July 21, 2018 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brahbassim/2733ffd37b33071ccaf3f413222aa0c4 to your computer and use it in GitHub Desktop.
Save brahbassim/2733ffd37b33071ccaf3f413222aa0c4 to your computer and use it in GitHub Desktop.
A gist to create confirmation js with sweet alert
// Add .delete-confirm class to your delete button or href
<script>
// Swal
$('.delete-confirm').on('click', function(e) {
var href = this;
e.preventDefault();
swal({
title: "Êtes-vous sûr?",
text: "Après suppression l'article ne sera plus accessible",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#e74c3c',
cancelButtonText: "Non, annuler!",
confirmButtonText: "Oui, supprimer!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm) {
if (isConfirm) {
window.location.href = href;
} else {
swal("Annulation", "Vous avez annuler la suppression :)", "success");
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment