Fix a bug where input class was propagating to the wrapper, closes #381
This commit is contained in:
parent
f41cbd4e7b
commit
031e3324ca
|
@ -20,7 +20,7 @@ module SimpleForm
|
|||
include SimpleForm::Components::Readonly
|
||||
|
||||
attr_reader :attribute_name, :column, :input_type, :reflection,
|
||||
:options, :input_html_options, :input_html_classes
|
||||
:options, :input_html_options, :input_html_classes, :html_classes
|
||||
|
||||
delegate :template, :object, :object_name, :lookup_model_names, :lookup_action, :to => :@builder
|
||||
|
||||
|
@ -61,7 +61,8 @@ module SimpleForm
|
|||
# Notice that html_options_for receives a reference to input_html_classes.
|
||||
# This means that classes added dynamically to input_html_classes will
|
||||
# still propagate to input_html_options.
|
||||
@input_html_classes = [input_type, required_class, readonly_class, disabled_class].compact
|
||||
@html_classes = [input_type, required_class, readonly_class, disabled_class].compact
|
||||
@input_html_classes = @html_classes.dup
|
||||
@input_html_options = html_options_for(:input, input_html_classes).tap do |o|
|
||||
o[:readonly] = true if has_readonly?
|
||||
o[:disabled] = true if has_disabled?
|
||||
|
|
|
@ -24,7 +24,7 @@ module SimpleForm
|
|||
|
||||
def html_classes(input, options)
|
||||
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
|
||||
css += input.input_html_classes
|
||||
css += input.html_classes
|
||||
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
|
||||
css
|
||||
end
|
||||
|
|
|
@ -188,6 +188,12 @@ class FormBuilderTest < ActionView::TestCase
|
|||
assert_select 'form input#my_input.my_input.string'
|
||||
end
|
||||
|
||||
test 'builder should not propagate input options to wrapper' do
|
||||
with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
|
||||
assert_no_select 'form div.input.my_input.string'
|
||||
assert_select 'form input#my_input.my_input.string'
|
||||
end
|
||||
|
||||
test 'builder should generate a input with label' do
|
||||
with_form_for @user, :name
|
||||
assert_select 'form label.string[for=user_name]', /Name/
|
||||
|
|
Loading…
Reference in New Issue