Skip to content

Commit c6f03be

Browse files
committed
Properly check if there's error on input.
Aslo if there's no error class setup on wrapper then there's no need to check for errors.
1 parent 4c10d27 commit c6f03be

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/simple_form/wrappers/many.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ def html_options(options)
6868

6969
def html_classes(input, options)
7070
css = @defaults[:class].dup
71-
css << @defaults[:error_class].dup { input.has_errors? }
71+
72+
if @defaults[:error_class] && input.has_errors?
73+
css << @defaults[:error_class]
74+
end
75+
7276
css.compact
7377
end
7478
end

test/form_builder/wrapper_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,11 @@ class WrapperTest < ActionView::TestCase
382382
assert_select 'section.custom_wrapper div.custom_error'
383383
end
384384
end
385+
386+
test 'inline wrapper has no error class when there is no error' do
387+
swap_wrapper :default, custom_wrapper_with_error_class do
388+
with_form_for @user, :email
389+
assert_no_select 'section.custom_wrapper div.custom_error'
390+
end
391+
end
385392
end

0 commit comments

Comments
 (0)