prevent generating class=""
This commit is contained in:
parent
c9562055b4
commit
4cb4a5ed5d
|
@ -119,7 +119,7 @@ module SimpleForm
|
|||
html_options = options[:"#{namespace}_html"]
|
||||
html_options = html_options ? html_options.dup : {}
|
||||
css_classes << html_options[:class] if html_options.key?(:class)
|
||||
html_options[:class] = css_classes
|
||||
html_options[:class] = css_classes unless css_classes.empty?
|
||||
html_options
|
||||
end
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module SimpleForm
|
|||
css += SimpleForm.additional_classes_for(:wrapper) { input.html_classes }
|
||||
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
|
||||
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
|
||||
css
|
||||
css.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -181,6 +181,13 @@ class IsolatedLabelTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'label should not generate empty css class' do
|
||||
swap SimpleForm, :generate_additional_classes_for => [:wrapper, :input] do
|
||||
with_label_for @user, :name, :string
|
||||
assert_no_select 'label[class]'
|
||||
end
|
||||
end
|
||||
|
||||
test 'label should obtain required from ActiveModel::Validations when it is included' do
|
||||
with_label_for @validating_user, :name, :string
|
||||
assert_select 'label.required'
|
||||
|
|
|
@ -75,6 +75,15 @@ class WrapperTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'wrapper should not generate empty css class' do
|
||||
swap SimpleForm, :generate_additional_classes_for => [:input, :label] do
|
||||
swap_wrapper :default, custom_wrapper_without_class do
|
||||
with_form_for @user, :name
|
||||
assert_no_select 'div#custom_wrapper_without_class[class]'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Custom wrapper test
|
||||
|
||||
test 'custom wrappers works' do
|
||||
|
|
|
@ -66,4 +66,12 @@ class InputTest < ActionView::TestCase
|
|||
with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos']
|
||||
assert_select 'select.select#project_name'
|
||||
end
|
||||
|
||||
test 'input should not generate empty css class' do
|
||||
swap SimpleForm, :generate_additional_classes_for => [:wrapper, :label] do
|
||||
with_input_for :project, :name, :string
|
||||
assert_no_select 'input#project_name[class]'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -72,6 +72,12 @@ module MiscHelpers
|
|||
end
|
||||
end
|
||||
|
||||
def custom_wrapper_without_class
|
||||
SimpleForm.build :tag => :div, :wrapper_html => { :id => 'custom_wrapper_without_class' } do |b|
|
||||
b.use :label_input
|
||||
end
|
||||
end
|
||||
|
||||
def custom_wrapper_with_label_html_option
|
||||
SimpleForm.build :tag => :div, :class => "custom_wrapper", :label_html => { :class => 'extra-label-class' } do |b|
|
||||
b.use :label_input
|
||||
|
|
Loading…
Reference in New Issue