Created
October 29, 2018 08:10
-
-
Save shah743/f97074a9b8127e1b768483c6dded95fb to your computer and use it in GitHub Desktop.
SweetAlert2 rails confirm
This file contains 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
$.rails.allowAction = (link) -> | |
if link.data('confirm') | |
$.rails.showConfirmationDialog(link) | |
false | |
else | |
true | |
# User click confirm button | |
$.rails.confirmed = (link) -> | |
link.data('confirm', null) | |
link.trigger('click') | |
# Display the confirmation dialog | |
$.rails.showConfirmationDialog = (link) -> | |
message = link.data('confirm') | |
title = link.data('title') || 'Warning' | |
swal( | |
title: title | |
text: message | |
type: 'warning' | |
showCancelButton: true | |
closeOnConfirm: false | |
confirmButtonColor: '#3085d6' | |
cancelButtonColor: '#d33' | |
confirmButtonText: 'Yes, delete it!' | |
).then (result) -> | |
if result.value | |
swal 'Deleted!', 'Record deleted successfully', 'success' | |
$.rails.confirmed(link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment