Skip to content

Instantly share code, notes, and snippets.

@kascote
Created October 2, 2017 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kascote/c44c0ffc83f472229f22ffca9e254b95 to your computer and use it in GitHub Desktop.
Save kascote/c44c0ffc83f472229f22ffca9e254b95 to your computer and use it in GitHub Desktop.
Replace Rails 5 alert dialog
promiseBasedConfirmPopup = new Promise((resolve) => {
// Show a nice popup and resolve to true/false
setTimeout(() => resolve(true), 2000)
})
$("a[data-confirm]").on("confirm", function(evt) {
// evt.target hold the clicked anchor from where
// can be extracted some data to build the popup
promiseBasedConfirmPopup().then((res) => {
if (res) {
// execute default handler if promise resolve true
// https://github.com/rails/rails/blob/v5.1.4/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
Rails.handleMethod.apply(evt.target, [evt])
}
})
// this is key, return false to disable default confirm dialog
// https://github.com/rails/rails/blob/v5.1.4/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee#L22
return false
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment