Skip to content

Instantly share code, notes, and snippets.

@stevenspiel
Last active January 25, 2016 12:46
Show Gist options
  • Save stevenspiel/af1c25835b716205cad2 to your computer and use it in GitHub Desktop.
Save stevenspiel/af1c25835b716205cad2 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.
# Override the default confirm dialog by rails
$.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'
sweetAlert
title: title
html: message
type: 'warning'
showCancelButton: true
confirmButtonColor: '#DD6B55'
confirmButtonText: 'Yes'
closeOnConfirm: true
animation: false
, ->
$.rails.confirmed(link)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment