Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

fix(buttons): ask once before a form button submits

Guido Boyke6ad860bf2ed8
diff --git a/app/components/neo/buttons/base.rb b/app/components/neo/buttons/base.rb
index 9f401c2..9fe502d 100644
--- a/app/components/neo/buttons/base.rb
+++ b/app/components/neo/buttons/base.rb
@@ -143,6 +143,15 @@ module Neo
].compact.join(' ')
end
+ # The button inside a form: (button_to). The confirmation belongs to the
+ # form (data-turbo-confirm); the button's own confirm would ask a second
+ # time before Turbo asks again.
+ def form_button_attributes
+ attrs = component_attributes.except(:href, :type)
+ attrs[:data]&.delete(:neo_button_confirm_value)
+ attrs
+ end
+
def component_attributes
attrs = @options.except(:class).dup
diff --git a/app/components/neo/buttons/button_component.html.erb b/app/components/neo/buttons/button_component.html.erb
index 7f47507..445e815 100644
--- a/app/components/neo/buttons/button_component.html.erb
+++ b/app/components/neo/buttons/button_component.html.erb
@@ -4,7 +4,7 @@
params: @form[:params],
class: component_classes,
form: { data: { turbo_confirm: @confirm }.compact.merge(@form[:data] || {}) },
- **component_attributes.except(:href, :type) do %>
+ **form_button_attributes do %>
<%= render_spinner(visible: @loading) %>
<%= render_icon(:left) %>
<span data-neo-button-target="content">
diff --git a/spec/components/neo/buttons/button_component_form_spec.rb b/spec/components/neo/buttons/button_component_form_spec.rb
index b26e904..613796a 100644
--- a/spec/components/neo/buttons/button_component_form_spec.rb
+++ b/spec/components/neo/buttons/button_component_form_spec.rb
@@ -74,11 +74,14 @@ RSpec.describe 'Neo::Buttons::ButtonComponent with form', type: :component do
}
end
- it 'applies Stimulus controller to the button' do
+ # The controller stays (loading state); the question is asked ONCE, by the
+ # form. The button's own confirm asked a second time (until 26.10.2026).
+ it 'applies Stimulus controller to the button and leaves the question to the form' do
rendered_component
expect(page).to have_css("form button[data-controller='neo-button']")
- expect(page).to have_css("form button[data-neo-button-confirm-value='Really delete?']")
+ expect(page).to have_css("form[data-turbo-confirm='Really delete?']")
+ expect(page).to have_no_css('form button[data-neo-button-confirm-value]')
expect(page).to have_css("form button[data-action='click->neo-button#handleClick']")
end
end
diff --git a/spec/components/neo/buttons/button_component_spec.rb b/spec/components/neo/buttons/button_component_spec.rb
index 9732a89..365cecb 100644
--- a/spec/components/neo/buttons/button_component_spec.rb
+++ b/spec/components/neo/buttons/button_component_spec.rb
@@ -294,6 +294,21 @@ RSpec.describe Neo::Buttons::ButtonComponent, type: :component do
end
end
+ # A button with form: renders a real form, and the confirmation sits on the
+ # form (data-turbo-confirm). Until 26.10.2026 the button ALSO carried
+ # neo-button's own confirm, so a delete asked twice.
+ describe 'form button with confirmation' do
+ let(:options) { { confirm: 'Delete this?', form: { action: '/things/1', method: :delete } } }
+
+ it 'asks once, through the form' do
+ rendered_component
+
+ expect(page).to have_css("form[data-turbo-confirm='Delete this?']")
+ expect(page).to have_css('form button')
+ expect(page).to have_no_css('button[data-neo-button-confirm-value]')
+ end
+ end
+
describe 'complex scenarios' do
context 'form submit button with icon and confirmation' do
let(:options) do