Skip to content

Commit 4d97163

Browse files
committed
feat: pass extra alert_message keywords to div
1 parent 86f15b2 commit 4d97163

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎lib/bootstrap_form/helpers/bootstrap.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def alert_message(title, options={})
99
css = options[:class] || "alert alert-danger"
1010
return unless object.respond_to?(:errors) && object.errors.full_messages.any?
1111

12-
tag.div class: css, tabindex: "-1" do
12+
tag.div class: css, **options.except(:class, :error_summary) do
1313
if options[:error_summary] == false
1414
title
1515
else

‎test/bootstrap_form_test.rb‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,23 @@ def warn(message, ...)
593593
assert_equivalent_html expected, @builder.alert_message("Please fix the following errors:", class: "my-css-class")
594594
end
595595

596+
test "alert_message passes extra options through as HTML attributes" do
597+
@user.email = nil
598+
assert @user.invalid?
599+
600+
expected = <<~HTML
601+
<div class="alert alert-danger" tabindex="-1" role="note">
602+
<p>Please fix the following errors:</p>
603+
<ul class="rails-bootstrap-forms-error-summary">
604+
<li>Email can't be blank</li>
605+
<li>Email is too short (minimum is 5 characters)</li>
606+
<li>Terms must be accepted</li>
607+
</ul>
608+
</div>
609+
HTML
610+
assert_equivalent_html expected, @builder.alert_message("Please fix the following errors:", tabindex: "-1", role: "note")
611+
end
612+
596613
test "alert_message contains the error summary when inline_errors are turned off" do
597614
@user.email = nil
598615
assert @user.invalid?

0 commit comments

Comments
 (0)