Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error_class work on inner wrapper #1729

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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? }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
css << @defaults[:error_class].dup { input.has_errors? }
css << @defaults[:error_class] if 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