diff --git a/lib/bootstrap_form/helpers/bootstrap.rb b/lib/bootstrap_form/helpers/bootstrap.rb index 7f3d7d3f..d5c62749 100644 --- a/lib/bootstrap_form/helpers/bootstrap.rb +++ b/lib/bootstrap_form/helpers/bootstrap.rb @@ -75,9 +75,10 @@ def prepend_and_append_input(name, options, &) input = capture(&) || ActiveSupport::SafeBuffer.new input = attach_input(options, :prepend) + input + attach_input(options, :append) - input << generate_error(name, id) + error = generate_error(name, id) + input << error options.present? && - input = tag.div(input, class: ["input-group", options[:input_group_class]].compact) + input = tag.div(input, class: ["input-group", ("has-validation" if error), options[:input_group_class]].compact) input end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index acc9d102..e844279d 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -195,7 +195,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
-
+
$ .00 @@ -207,6 +207,24 @@ class BootstrapFormGroupTest < ActionView::TestCase assert_equivalent_html expected, bootstrap_form_for(@user) { |f| f.text_field :email, prepend: "$", append: ".00" } end + test "adding prepend text with validation error and inline errors turned off" do + @user.email = nil + assert @user.invalid? + + expected = <<~HTML + +
+ +
+ $ + +
+
+ + HTML + assert_equivalent_html expected, bootstrap_form_for(@user, inline_errors: false) { |f| f.text_field :email, prepend: "$" } + end + test "file field with prepend text" do expected = <<~HTML