Skip to content

Commit

Permalink
Properly check if there's error on input.
Browse files Browse the repository at this point in the history
Aslo if there's no error class setup on wrapper then there's
no need to check for errors.
  • Loading branch information
nashby committed Oct 2, 2022
1 parent 4c10d27 commit c6f03be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/simple_form/wrappers/many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ def html_options(options)

def html_classes(input, options)
css = @defaults[:class].dup
css << @defaults[:error_class].dup { input.has_errors? }

if @defaults[:error_class] && input.has_errors?
css << @defaults[:error_class]
end

css.compact
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 @@ -382,4 +382,11 @@ class WrapperTest < ActionView::TestCase
assert_select 'section.custom_wrapper div.custom_error'
end
end

test 'inline wrapper has no error class when there is no error' do
swap_wrapper :default, custom_wrapper_with_error_class do
with_form_for @user, :email
assert_no_select 'section.custom_wrapper div.custom_error'
end
end
end

0 comments on commit c6f03be

Please sign in to comment.