Skip to content

Instantly share code, notes, and snippets.

@shah743
Created October 29, 2018 08:10
Show Gist options
  • Save shah743/f97074a9b8127e1b768483c6dded95fb to your computer and use it in GitHub Desktop.
Save shah743/f97074a9b8127e1b768483c6dded95fb to your computer and use it in GitHub Desktop.
SweetAlert2 rails confirm
$.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