How to add additional custom ContentSlots #52
-
Hi, thank you for your library. I tried to create so something like this as a workaround, render another dialog and <% dialog_id ||= "confirm" %>
<dialog id="<%= dialog_id %>" class="modal" data-controller="dialog" data-action="click@window->dialog#handleOutsideClick"> .... and call it like this <%= button_to subscription_path(subscription),
data: {
turbo_method: :delete,
turbo_confirm: "Cancel this subscription?",
confirm_details: "Are you sure you want to cancel this subscription?",
confirm_button: "11Yes, I'm sure",
dialogSelector: "#confirmUnsubscribe",
but received
PS: if what I need is still possible, I wish the documentation contained more examples. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @igorkasyanchuk! You can do this using contentSlots. I realize the documentation could use some examples in this area, but it works like this: You'll need to pass a config object into the import '@hotwired/turbo-rails'
import TC from '@rolemodel/turbo-confirm'
TC.start({
contentSlots: {
body: {
contentAttribute: 'confirm-details',
slotSelector: '#confirm-body'
},
acceptText: {
contentAttribute: 'confirm-button',
slotSelector: '#confirm-accept'
},
rejectText: {
contentAttribute: 'confirm-cancel',
slotSelector: '#confirm-cancel'
}
}
})
Taking a closer look at our new custom content slot: rejectText: {
contentAttribute: 'confirm-cancel',
slotSelector: '#confirm-cancel'
} The name
So given the above example, we're telling TurboConfirm to look for a Tying this back to your original question & with the additional contentSlot defined, your original code can be updated to use it like this: <%= button_to subscription_path(subscription),
data: {
turbo_method: :delete,
turbo_confirm: "Cancel this subscription?",
confirm_details: "Are you sure you want to cancel this subscription?",
confirm_button: "Yes, I'm sure",
confirm_cancel: "Close",
}
%> Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey @igorkasyanchuk!
You can do this using contentSlots. I realize the documentation could use some examples in this area, but it works like this:
You'll need to pass a config object into the
start
function:body
&acceptText
are already defined by default, but they'll be overrid…