Skip to content

Instantly share code, notes, and snippets.

@phanviet
Last active June 16, 2016 02:22
Show Gist options
  • Save phanviet/135d7e89051d142f3240ddb932cc1951 to your computer and use it in GitHub Desktop.
Save phanviet/135d7e89051d142f3240ddb932cc1951 to your computer and use it in GitHub Desktop.
Custom Confirm Alert Default in Rails
//Override the default confirm dialog by rails
(function () {
$.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");
// hide your custom confirm dialog
$('.confirm_modal').modal('hide');
}
//Display the confirmation dialog
$.rails.showConfirmationDialog = function(link){
var message = link.data("confirm");
// Display your confirm dialog and pass message if you want
var $confirmModal = $('.confirm_modal');
$confirmModal.modal('show');
// Handle OK button in modal and trigger action
// $.rails.confirmed(link);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment