Clicking on "Destroy" button from index collection table causes a redirect to resource page. This happens after the confirmation browser alert is closed, both when confirming delete and cancelling delete.
This happens when using default administrate templates. In addition the same bug would be visible when using custom collection view partial that adds additional actions that are rendered not as links with href tag.
Stack to reproduce it: administrate v1.0.0, Rails 8.1 (I'm using assets bundled with administrate with propshaft).
Why it happens
Stimulus click->table#visitDataUrl action attached to _collection partial only considers target with href attribute as a condition when the url visit should not apply. This conflicts with _collection_items_actions partial that renders destroy action as button_to (which doesn't have href attribute).
Possible solutions
idea 1: change _collection_items_actions partial to use link_to instead of button_to for destroy action
- this can be used as a temporary workaround in an application, as the partial can be customized easily
- drawback: delete is now a link instead of form submit
<% if existing_action?(collection_presenter.resource_name, :edit) %>
<td class="cell-label--action-button"><%= link_to(
t("administrate.actions.edit"),
[:edit, namespace, resource],
class: "action-edit",
) if accessible_action?(resource, :edit) %></td>
<% end %>
<% if existing_action?(collection_presenter.resource_name, :destroy) %>
<td class="cell-label--action-button"><%= link_to(
t("administrate.actions.destroy"),
[namespace, resource],
class: "link link--danger",
data: { turbo_method: :delete, turbo_confirm: t("administrate.actions.confirm") }
) if accessible_action?(resource, :destroy) %></td>
<% end %>
idea 2: change visitDataUrl action in table_controller to exclude targets that are buttons or allow configuration for targets
event.target.tagName == 'BUTTON' or event.target.type == 'submit' could be used as an OR condition to the existing early return
- even better would be to extend the existing early return condition check with some target configuration (data attribute or some kind of Stimulus property) that would disable the url visit, e.g. consider a custom tag that triggers modal opening (added in a custom
_collection_items_actions partial)
<span data-bs-toggle="modal" data-bs-target="my-resource-modal" data-disable-url-visit="true">
Open my modal
</span>
Clicking on "Destroy" button from index collection table causes a redirect to resource page. This happens after the confirmation browser alert is closed, both when confirming delete and cancelling delete.
This happens when using default administrate templates. In addition the same bug would be visible when using custom collection view partial that adds additional actions that are rendered not as links with
hreftag.Stack to reproduce it: administrate v1.0.0, Rails 8.1 (I'm using assets bundled with administrate with propshaft).
Why it happens
Stimulus
click->table#visitDataUrlaction attached to_collectionpartial only considers target withhrefattribute as a condition when the url visit should not apply. This conflicts with_collection_items_actionspartial that renders destroy action asbutton_to(which doesn't havehrefattribute).Possible solutions
idea 1: change
_collection_items_actionspartial to uselink_toinstead ofbutton_tofor destroy actionidea 2: change
visitDataUrlaction intable_controllerto exclude targets that are buttons or allow configuration for targetsevent.target.tagName == 'BUTTON'orevent.target.type == 'submit'could be used as an OR condition to the existing early return_collection_items_actionspartial)