Skip to content

Commit

Permalink
Make error_class work on inner wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
coupling committed Mar 12, 2021
1 parent 886713c commit 4c10d27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/simple_form/wrappers/many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def html_options(options)
end

def html_classes(input, options)
@defaults[:class].dup
css = @defaults[:class].dup
css << @defaults[:error_class].dup { input.has_errors? }
css.compact
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions test/form_builder/wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,11 @@ class WrapperTest < ActionView::TestCase
assert_no_select 'p.omg_hint'
end
end

test 'inline wrapper has an error class' do
swap_wrapper :default, custom_wrapper_with_error_class do
with_form_for @user, :name
assert_select 'section.custom_wrapper div.custom_error'
end
end
end
8 changes: 8 additions & 0 deletions test/support/misc_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def custom_wrapper_with_unless_blank
end
end

def custom_wrapper_with_error_class
SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
b.wrapper tag: :div, error_class: 'custom_error' do |ba|
ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
end
end
end

def custom_wrapper_with_input_class
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
b.use :label
Expand Down

0 comments on commit 4c10d27

Please sign in to comment.