Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shah743/62f4815c7457fc4360c1 to your computer and use it in GitHub Desktop.
Save shah743/62f4815c7457fc4360c1 to your computer and use it in GitHub Desktop.
Replace Rails confirm with sweetalert2 popup. (https://github.com/limonte/sweetalert2). It overrides the default javascript (from jquery_ujs), which skips any other popup.
$.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
confirmButtonColor: '#3085d6'
cancelButtonColor: '#d33'
confirmButtonText: 'Yes, delete it!'
closeOnConfirm: false
}, ->
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