From 8715d10a013713ef62c26d4d42ef668b9e6679c7 Mon Sep 17 00:00:00 2001 From: Jonas Pardeyke Date: Thu, 27 Nov 2025 01:14:44 +0100 Subject: [PATCH 1/2] adding a configuration option to use turbo_submits_with --- README.md | 1 + lib/bootstrap_form/configuration.rb | 19 +++++++++++++++++++ lib/bootstrap_form/inputs/submit.rb | 5 ++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b233c2d3..930e4e4a 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,7 @@ The current configuration options are: | Option | Default value | Description | |---------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `default_form_attributes` | {} | `bootstrap_form` versions 3 and 4 added a role="form" attribute to all forms. The W3C validator will raise a **warning** on forms with a role="form" attribute. `bootstrap_form` version 5 drops this attribute by default. Set this option to `{ role: "form" }` to make forms non-compliant with W3C, but generate the `role="form"` attribute like `bootstrap_form` versions 3 and 4. | +| `turbo_submits_with` | {} | Add custom content to a submit button while the request is processing. Try `c.turbo_submits_with = :spinner` to check out the build-in spinner or pass a custom html string. Caveat: Only works on `form.primary` or `form.button` as `form.submit` renders a `input` file which only accepts a string and not a html element. Settings this also overrides `render_as_button` on `form.primary` | Example: diff --git a/lib/bootstrap_form/configuration.rb b/lib/bootstrap_form/configuration.rb index fdd2e0d2..d5a73689 100644 --- a/lib/bootstrap_form/configuration.rb +++ b/lib/bootstrap_form/configuration.rb @@ -25,6 +25,25 @@ def default_form_attributes MESSAGE BootstrapForm.config.default_form_attributes end + + def turbo_submits_with=(value) + case value + when nil + @turbo_submits_with = nil + when :spinner, "spinner" + @turbo_submits_with = "
Loading...
" + when Symbol, String + @turbo_submits_with = value.to_s + else + raise ArgumentError, "Unsupported turbo_submits_with #{value.inspect}" + end + end + + def turbo_submits_with + return @turbo_submits_with if defined? @turbo_submits_with + + nil + end end mattr_accessor :config, default: ActiveSupport::OrderedOptions.new diff --git a/lib/bootstrap_form/inputs/submit.rb b/lib/bootstrap_form/inputs/submit.rb index 24c196d2..71ec812b 100644 --- a/lib/bootstrap_form/inputs/submit.rb +++ b/lib/bootstrap_form/inputs/submit.rb @@ -4,6 +4,9 @@ module BootstrapForm module Inputs module Submit def button(value=nil, options={}, &) + if BootstrapForm.config.turbo_submits_with + options.merge! data: { turbo_submits_with: BootstrapForm.config.turbo_submits_with } + end value = setup_css_class "btn btn-secondary", value, options super end @@ -16,7 +19,7 @@ def submit(value=nil, options={}) def primary(value=nil, options={}, &block) value = setup_css_class "btn btn-primary", value, options - if options[:render_as_button] || block + if options[:render_as_button] || block || BootstrapForm.config.turbo_submits_with options.except! :render_as_button button(value, options, &block) else From 6abf7b25d6d2383bfd6f00725a5b7fb3c382b76a Mon Sep 17 00:00:00 2001 From: Jonas Pardeyke <142009152+pardeyke@users.noreply.github.com> Date: Thu, 27 Nov 2025 09:38:19 +0100 Subject: [PATCH 2/2] Update README.md Co-authored-by: Larry Reid --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 930e4e4a..3f001b9d 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ The current configuration options are: | Option | Default value | Description | |---------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `default_form_attributes` | {} | `bootstrap_form` versions 3 and 4 added a role="form" attribute to all forms. The W3C validator will raise a **warning** on forms with a role="form" attribute. `bootstrap_form` version 5 drops this attribute by default. Set this option to `{ role: "form" }` to make forms non-compliant with W3C, but generate the `role="form"` attribute like `bootstrap_form` versions 3 and 4. | -| `turbo_submits_with` | {} | Add custom content to a submit button while the request is processing. Try `c.turbo_submits_with = :spinner` to check out the build-in spinner or pass a custom html string. Caveat: Only works on `form.primary` or `form.button` as `form.submit` renders a `input` file which only accepts a string and not a html element. Settings this also overrides `render_as_button` on `form.primary` | +| `turbo_submits_with` | {} | Add custom content to a submit button while the request is processing. Try `c.turbo_submits_with = :spinner` to use the built-in spinner, or pass a custom HTML string. Caveat: Only works on `form.primary` or `form.button` as `form.submit` renders a `input` field which only accepts a string and not an HTML element. Settings this also forces `render_as_button` on `form.primary` | Example: