From d2e6aa24d44fdb194fa386aead2ce9b1661211d1 Mon Sep 17 00:00:00 2001 From: Gareth Jones <3151613+G-Rath@users.noreply.github.com> Date: Tue, 30 Jun 2026 09:10:01 +1200 Subject: [PATCH 1/4] fix: make alert message focusable for accessibility --- lib/bootstrap_form/helpers/bootstrap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bootstrap_form/helpers/bootstrap.rb b/lib/bootstrap_form/helpers/bootstrap.rb index 1cf39ce4..f83893c8 100644 --- a/lib/bootstrap_form/helpers/bootstrap.rb +++ b/lib/bootstrap_form/helpers/bootstrap.rb @@ -9,7 +9,7 @@ def alert_message(title, options={}) css = options[:class] || "alert alert-danger" return unless object.respond_to?(:errors) && object.errors.full_messages.any? - tag.div class: css do + tag.div class: css, tabindex: "-1" do if options[:error_summary] == false title else From 40cf5dfb541f816fd921c74729724d85abd293f1 Mon Sep 17 00:00:00 2001 From: Gareth Jones <3151613+G-Rath@users.noreply.github.com> Date: Tue, 29 Sep 2026 15:21:49 +1300 Subject: [PATCH 2/4] feat: pass extra `alert_message` keywords to `div` --- lib/bootstrap_form/helpers/bootstrap.rb | 2 +- test/bootstrap_form_test.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/bootstrap_form/helpers/bootstrap.rb b/lib/bootstrap_form/helpers/bootstrap.rb index f83893c8..7f3d7d3f 100644 --- a/lib/bootstrap_form/helpers/bootstrap.rb +++ b/lib/bootstrap_form/helpers/bootstrap.rb @@ -9,7 +9,7 @@ def alert_message(title, options={}) css = options[:class] || "alert alert-danger" return unless object.respond_to?(:errors) && object.errors.full_messages.any? - tag.div class: css, tabindex: "-1" do + tag.div class: css, **options.except(:class, :error_summary) do if options[:error_summary] == false title else diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 33d04f23..979d9bd1 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -593,6 +593,23 @@ def warn(message, ...) assert_equivalent_html expected, @builder.alert_message("Please fix the following errors:", class: "my-css-class") end + test "alert_message passes extra options through as HTML attributes" do + @user.email = nil + assert @user.invalid? + + expected = <<~HTML +
+

Please fix the following errors:

+ +
+ HTML + assert_equivalent_html expected, @builder.alert_message("Please fix the following errors:", tabindex: "-1", role: "note") + end + test "alert_message contains the error summary when inline_errors are turned off" do @user.email = nil assert @user.invalid? From ee4b5356f73686324c26aecf0559c6dcaf14156c Mon Sep 17 00:00:00 2001 From: Gareth Jones <3151613+G-Rath@users.noreply.github.com> Date: Thu, 1 Oct 2026 13:28:35 +1300 Subject: [PATCH 3/4] docs: add section to readme --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 6bd40fda..957c0d51 100644 --- a/README.md +++ b/README.md @@ -1614,6 +1614,29 @@ This generates: ``` +Additional options will be passed on as attributes to the root `div`: + +```erb +<%= bootstrap_form_for @user_with_error do |f| %> + <%= f.alert_message "Please fix the errors below.", tabindex: -1, role: "note" %> +<% end %> +``` + +This generates: + +```html +
+
+

Please fix the errors below.

+ +
+
+``` + To output a simple unordered list of errors, use the `error_summary` helper. ![Example 51](demo/doc/screenshots/bootstrap/readme/51_example.png "Example 51") From 5995353483003d2b142abd8902c92e7e9c1231d3 Mon Sep 17 00:00:00 2001 From: Gareth Jones <3151613+G-Rath@users.noreply.github.com> Date: Fri, 2 Oct 2026 15:39:52 +1300 Subject: [PATCH 4/4] docs: use existing example --- README.md | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 957c0d51..5d868003 100644 --- a/README.md +++ b/README.md @@ -1573,12 +1573,12 @@ By default, turning on `:label_errors` will also turn off To display an error message with an error summary, you can use the `alert_message` helper. This won't output anything unless a model validation -has failed. +has failed, and additional options will be passed on as attributes to the root `div`: ![Example 49](demo/doc/screenshots/bootstrap/readme/49_example.png "Example 49") ```erb <%= bootstrap_form_for @user_with_error do |f| %> - <%= f.alert_message "Please fix the errors below." %> + <%= f.alert_message "Please fix the errors below.", tabindex: -1, role: "note" %> <% end %> ``` @@ -1586,7 +1586,7 @@ Which outputs: ```html
-
+

Please fix the errors below.

  • Email is invalid
  • @@ -1614,29 +1614,6 @@ This generates: ``` -Additional options will be passed on as attributes to the root `div`: - -```erb -<%= bootstrap_form_for @user_with_error do |f| %> - <%= f.alert_message "Please fix the errors below.", tabindex: -1, role: "note" %> -<% end %> -``` - -This generates: - -```html -
    -
    -

    Please fix the errors below.

    -
      -
    • Email is invalid
    • -
    • Misc is invalid
    • -
    • Preferences is invalid
    • -
    -
    -
    -``` - To output a simple unordered list of errors, use the `error_summary` helper. ![Example 51](demo/doc/screenshots/bootstrap/readme/51_example.png "Example 51")