Skip to content

Commit

Permalink
Ensure to generate input_class only for the input, not for the wrapper
Browse files Browse the repository at this point in the history
Thanks @ollym for catching this one. Related to heartcombo#337.

Conflicts:
	CHANGELOG.md
  • Loading branch information
carlosantoniodasilva authored and butsjoh committed Nov 28, 2013
1 parent 6b9b4af commit 3d0ab5c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### enhancements
* Add wrapper mapping per form basis [@rcillo](https://github.com/rcillo) and [@bernardoamc](https://github.com/bernardoamc)
* New `input_class` global config option to set a class to be generated in all inputs.
* New `input_class` global config option to set a class to be generated in all inputs.
* `input_field` supports `html5` component [@nashby](https://github.com/nashby)
* Add `include_default_input_wrapper_class` config [@luizcosta](https://github.com/luizcosta)

Expand Down
6 changes: 5 additions & 1 deletion lib/simple_form/inputs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def initialize(builder, attribute_name, column, input_type, options = {})
@html_classes = SimpleForm.additional_classes_for(:input) { additional_classes }

@input_html_classes = @html_classes.dup
if SimpleForm.input_class && !input_html_classes.empty?
input_html_classes << SimpleForm.input_class
end

@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?
Expand All @@ -81,7 +85,7 @@ def input_options
end

def additional_classes
@additional_classes ||= [input_type, required_class, readonly_class, disabled_class, SimpleForm.input_class].compact
@additional_classes ||= [input_type, required_class, readonly_class, disabled_class].compact
end

def input_class
Expand Down
13 changes: 11 additions & 2 deletions test/inputs/general_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ class InputTest < ActionView::TestCase
assert_select 'input.string[autofocus]'
end

test 'input should accepts input class configuration' do
swap SimpleForm, :input_class => :xlarge do
test 'input accepts input_class configuration' do
swap SimpleForm, input_class: :xlarge do
with_input_for @user, :name, :string
assert_select 'input.xlarge'
assert_no_select 'div.xlarge'
end
end

test 'input does not add input_class when configured to not generate additional classes for input' do
swap SimpleForm, input_class: 'xlarge', generate_additional_classes_for: [:wrapper] do
with_input_for @user, :name, :string
assert_select 'input'
assert_no_select '.xlarge'
end
end

Expand Down

0 comments on commit 3d0ab5c

Please sign in to comment.