Hey @Alan_G,
Thank you very much for your response.
Our delete was a simple link/ahref which was using turbo_method: :delete to send a DELETE request instead of GET.
I found a workaround for the moment that is functional.
To make it work, I commented all buttons inside the popup form.
I created a new form just for the DELETE method.
I moved all submit buttons them outside the forms and I used the web-component onclick event to send the requestSubmit().
onclick="document.getElementById('edit_popup_version_form')?.requestSubmit();this.loading = true;"
I used the form="edit_popup_version_form" attribute which allows to submit a form with a button that’s outside that form, but I don’t think this works with the web-components. So the fallback method is the requestSubmit();
The regular submit button works as expected, however, the main problem was the remove button which wasn’t responding as expected since it was a regular link button that’s using the Hotwire / Turbo method of DELETE found in the data attributes.
<turbo-frame id="new_page">
<%= form_with(model: [@popup, popup_version], url: path, id: "edit_popup_version_form", data: { turbo_frame: "_top" }) do |form| %>
<%= render "shared/error_messages", resource: form.object %>
<%= form.hidden_field :popup_id, class: "form-input" %>
<div class="form-group mb-4">
<%= form.label :title, class: "text-sm" %>
<%= form.text_field :title, class: "form-input", placeholder: "Light Version" %>
</div>
<!-- All form actions are disabled and moved outside the form -->
<div class="form-group flex justify-between" data-turbo-prefetch="false">
<%# form.button "Save Version", class: "#{green_btn}" %>
<%# <s-button type="submit" variant="primary" onclick="this.loading = true;">Save version</s-button> %>
<% if form.object.persisted? %>
<%# method: :delete, %>
<!--<s-button href="<%= path %>" type="button" variant="primary" icon="delete" tone="critical">Delete version</s-button> -->
<%#link_to 'Remove Version', path, data: { turbo_method: :delete, turbo_confirm: "Are you sure?", turbo_frame: "_top" }, class: "#{red_btn}" %>
<% end %>
</div>
<% end %>
<%# DELETE FORM %>
<%= form_with(model: [@popup, popup_version], url: path, method: :delete, id: "remove_popup_version_form", data: { turbo_frame: "_top" }) do |form| %><% end %>
<div class="form-group flex justify-between" data-turbo-prefetch="false">
<s-button type="submit" variant="primary" form="edit_popup_version_form" onclick="document.getElementById('edit_popup_version_form')?.requestSubmit();this.loading = true;">Save version</s-button>
<s-button type="button" variant="primary" form="remove_popup_version_form" onclick="document.getElementById('remove_popup_version_form')?.requestSubmit();this.loading = true;" icon="delete" tone="critical">Delete version</s-button>
</div>
</turbo-frame>
Here is example that works as expected, but this is a simple submit.
<%= form_with url: app_charges_path(shop: @shop_origin, plan: "basic"), method: :post do |form| %>
<s-button type="submit" variant="secondary" onclick="this.loading">Activate Plan →</s-button>
<% end %>
In conclusion, the main problem is that Hotwire/Turbo doesn’t recognize the <s-button> when it has a href with dataset-attributes such as data-turbo-method="delete" or data-turbo-confirm="Are you Sure?" or data-turbo-frame="_top" even if we pass the data attributes to the component, they are not rendered in the actual link.
Here is another working example. The href doesn’t work, so I had to use the onclick with the Turbo visit function onclick="Turbo.visit('/app/contacts', { action: 'replace'})" as it shows on Turbo docs
<s-button
href="/app/contacts"
variant="tertiary"
tone="neutral"
onclick="Turbo.visit('/app/contacts', { action: 'replace'})">
Get free help
</s-button>
It happens that most of our projects are using StimulusReflex
and TurboBoost Comamnds and they are all using data attributes such as
I think if the data-attributes would be passed to the web-components slots it would work, but I’m not sure as I’m unable to test that.
So I’m wondering what would be the best way we could use the web-components inside our Rails apps with Hotwire and Turbo?
Thank you so much again for your time for looking into this!