Skip to content

Fix destroy button click navigating to show page on index#3026

Open
55728 wants to merge 1 commit intothoughtbot:mainfrom
55728:fix-destroy-button-row-navigation
Open

Fix destroy button click navigating to show page on index#3026
55728 wants to merge 1 commit intothoughtbot:mainfrom
55728:fix-destroy-button-row-navigation

Conversation

@55728
Copy link
Copy Markdown

@55728 55728 commented Apr 1, 2026

What

Fixes #2978

Clicking the "Destroy" button on the index page collection table
was navigating to the resource's show page instead of triggering
the delete action.

Why

The visitDataUrl action in table_controller.js checked
event.target.href to decide whether to skip row navigation.
Since button_to generates a <form> with a <button> (which
has no href attribute), the check was bypassed, causing
Turbo.visit(dataUrl) to fire.

How

Replaced event.target.href with
event.target.closest("a[href], button, input[type='submit']")
to properly detect interactive elements that should not trigger
row navigation. This also handles:

  • <button> elements (the reported bug)
  • <input type="submit"> elements (future safety)
  • Child elements inside links/buttons (e.g. icons)

Added a feature spec that verifies dismissing the destroy
confirmation keeps the user on the index page.

Changed files

  • app/assets/javascripts/administrate/controllers/table_controller.js (1 line)
  • spec/features/orders_index_spec.rb (+11 lines)

Clicking the Destroy button on the index collection table was triggering row navigation to the show page. The visitDataUrl Stimulus action only checked event.target.href to skip navigation, but button_to generates a <button> element without href.

Replace the href check with event.target.closest() to properly detect interactive elements (links, buttons, submit inputs) that should not trigger row navigation.

Fixes thoughtbot#2978
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting resource (from index collection table) redirects to resource page

1 participant