Created
June 16, 2016 01:07
-
-
Save phanviet/b7ab5df45f5dbe3107976b79101b6d66 to your computer and use it in GitHub Desktop.
Custom Confirm Alert Default in Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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