Custom [data-turbo-confirm] modal

Is there a straightforward way to tap into the data-turbo-confirm attribute to change out the modal with a styled one?

I know you can replace it globally (read it, not tried it myself):

But, not sure you can tap into it on a per-confirm basis.

Huh, I must have missed this in the docs. Overwriting everywhere is probably fine for my use case.

I’ve written a lightweight, open source package for this. GitHub - RoleModel/turbo-confirm: Dropin upgrade for Rails' data-turbo-confirm to support custom dialogs

1 Like

I’ve looked at the code to see whether the replacement function can be Promise-based, and it appears so!

That means you should be able to do something like (very roughly)

  () => import('confirm-dialog')
    .then(mod => mod.default.confirm("Are you sure?")) // confirm() can return its own Promise