Skip to content

Commit

Permalink
Merge pull request #1540 from plataformatec/frg-fix-collection-boolea…
Browse files Browse the repository at this point in the history
…n-style

Fix boolean inputs in nested style for label non-string
  • Loading branch information
feliperenan authored Feb 1, 2018
2 parents 983571b + 4f24349 commit 2500760
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Check if Rails.env is defined. [@etagwerker](https://github.com/etagwerker)
* Fix minlength. [@mameier](https://github.com/mameier)
* Make errors_on_attribute return [] when not present. [@redrick](https://github.com/redrick)
* Fix boolean inputs in nested style for label non-string. [@feliperenan](https://github.com/feliperenan)

## 3.5.0

Expand Down
2 changes: 1 addition & 1 deletion lib/simple_form/inputs/collection_check_boxes_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def has_required?
end

def build_nested_boolean_style_item_tag(collection_builder)
collection_builder.check_box + collection_builder.text
collection_builder.check_box + collection_builder.text.to_s
end

def item_wrapper_class
Expand Down
2 changes: 1 addition & 1 deletion lib/simple_form/inputs/collection_radio_buttons_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def collection_block_for_nested_boolean_style
end

def build_nested_boolean_style_item_tag(collection_builder)
collection_builder.radio_button + collection_builder.text
collection_builder.radio_button + collection_builder.text.to_s
end

def item_wrapper_class
Expand Down
15 changes: 15 additions & 0 deletions test/inputs/collection_check_boxes_input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,19 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
assert_select 'label[for=user_1_gender_female]'
end
end

test 'input check boxes with nested style accepts non-string attribute as label' do
swap SimpleForm, boolean_style: :nested do
with_input_for @user, :amount,
:check_boxes,
collection: { 100 => 'hundred', 200 => 'two_hundred' },
label_method: :first,
value_method: :second

assert_select 'input[type=checkbox][value=hundred]'
assert_select 'input[type=checkbox][value=two_hundred]'
assert_select 'span.checkbox > label', '100'
assert_select 'span.checkbox > label', '200'
end
end
end
15 changes: 15 additions & 0 deletions test/inputs/collection_radio_buttons_input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,19 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
assert_select 'label[for=user_1_gender_female]'
end
end

test 'input radio with nested style accetps non-string attribute as label' do
swap SimpleForm, boolean_style: :nested do
with_input_for @user, :amount,
:radio_buttons,
collection: { 100 => 'hundred', 200 => 'two_hundred' },
label_method: :first,
value_method: :second

assert_select 'input[type=radio][value=hundred]'
assert_select 'input[type=radio][value=two_hundred]'
assert_select 'span.radio > label', '100'
assert_select 'span.radio > label', '200'
end
end
end

0 comments on commit 2500760

Please sign in to comment.