Skip to content

Commit 4c10d27

Browse files
committed
Make error_class work on inner wrapper
1 parent 886713c commit 4c10d27

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/simple_form/wrappers/many.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def html_options(options)
6767
end
6868

6969
def html_classes(input, options)
70-
@defaults[:class].dup
70+
css = @defaults[:class].dup
71+
css << @defaults[:error_class].dup { input.has_errors? }
72+
css.compact
7173
end
7274
end
7375
end

test/form_builder/wrapper_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,11 @@ class WrapperTest < ActionView::TestCase
375375
assert_no_select 'p.omg_hint'
376376
end
377377
end
378+
379+
test 'inline wrapper has an error class' do
380+
swap_wrapper :default, custom_wrapper_with_error_class do
381+
with_form_for @user, :name
382+
assert_select 'section.custom_wrapper div.custom_error'
383+
end
384+
end
378385
end

test/support/misc_helpers.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def custom_wrapper_with_unless_blank
8585
end
8686
end
8787

88+
def custom_wrapper_with_error_class
89+
SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
90+
b.wrapper tag: :div, error_class: 'custom_error' do |ba|
91+
ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
92+
end
93+
end
94+
end
95+
8896
def custom_wrapper_with_input_class
8997
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
9098
b.use :label

0 commit comments

Comments
 (0)