Skip to main content

SweetAlert integration

Rails • Asked by Michael Kibet

I was able to intergrate sweetAlert properly(*not using the gem but by including the files manually in vendor *)and overiding the rails defaults as follows in the application.js file=>

$.rails.allowAction = function(link){
  if (link.data("confirm") == undefined){
    return true;
  }
  $.rails.showConfirmationDialog(link);
  return false;
}

//User click confirm button
$.rails.confirmed = function(link){
  link.data("confirm", null);
  link.trigger("click.rails");
}

//Display the confirmation dialog
$.rails.showConfirmationDialog = function(link){
  var message = link.data("confirm");
  swal({
    title: message,
    type: 'warning',
    confirmButtonText: 'Sure',
    confirmButtonColor: '#2acbb3',
    showCancelButton: true
  }).then(function(e){
    $.rails.confirmed(link);
  });
};

But the problem comes when I click on the delete button, the dialog box occurs for a very short and doesn't even allow me to either confirm nor deny.
*So I am asking how am i going to slow the dialog box down or make it persistent until a choice is made *


Hey Michael,

Not quite sure what's going on there, but any reason you're not using the gem? It already hooks into the standard rails data-confirm stuff and makes this seamless and you can customize the colors and buttons like usual.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.