Browse files

Merge branch 'kb-ek-change-wraper-collection'

  • Loading branch information...
2 parents 4052bc3 + 1b2c347 commit 7fa6e5fc83fd5e8d3e5aca41058e6ba21c7361df @erichkist erichkist committed Jan 6, 2014
View
1 CHANGELOG.md
@@ -1,6 +1,7 @@
## master
### enhancements
+ * For radio or checkbox collection always use `:item_wrapper_tag` to wrap the content and add `label` when using `boolean_style` with `:nested` [@kassio](https://github.com/kassio) and [@erichkist](https://github.com/erichkist)
* `input_field` uses the same wrapper as input but only with attribute components. [@nashby](https://github.com/nashby)
* Add wrapper mapping per form basis [@rcillo](https://github.com/rcillo) and [@bernardoamc](https://github.com/bernardoamc)
* Add `for` attribute to `label` when collections are rendered as radio or checkbox [@erichkist](https://github.com/erichkist), [@ulissesalmeida](https://github.com/ulissesalmeida) and [@fabioyamate](https://github.com/fabioyamate)
View
8 lib/simple_form/inputs/collection_radio_buttons_input.rb
@@ -13,7 +13,6 @@ def input
def input_options
options = super
apply_default_collection_options!(options)
- apply_nested_boolean_collection_options!(options) if nested_boolean_style?
options
end
@@ -31,13 +30,6 @@ def apply_default_collection_options!(options)
].compact.presence
end
- # Force item wrapper to be a label when using nested boolean, to support
- # configuring classes through :item_wrapper_class, and to maintain
- # compatibility with :inline style and default :item_wrapper_tag.
- def apply_nested_boolean_collection_options!(options)
- options[:item_wrapper_tag] = :label
- end
-
def collection_block_for_nested_boolean_style
return unless nested_boolean_style?
View
19 lib/simple_form/tags.rb
@@ -15,19 +15,14 @@ def render_collection
rendered_item = yield item, value, text, default_html_options.merge(additional_html_options)
- if item_wrapper_tag
- options = { class: item_wrapper_class }
-
- if item_wrapper_tag.to_s == 'label'
- label_options = {}
- add_default_name_and_id_for_value(value, label_options)
- options['for'] = label_options['id']
- end
-
- @template_object.content_tag(item_wrapper_tag, rendered_item, options)
- else
- rendered_item
+ if @options.fetch(:boolean_style, SimpleForm.boolean_style) == :nested
+ label_options = {}
+ add_default_name_and_id_for_value(value, label_options)
+ label_options['for'] = label_options['id']
+ rendered_item = content_tag(:label, rendered_item, label_options)
end
+
+ item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, class: item_wrapper_class) : rendered_item
end.join.html_safe
end
View
22 test/inputs/collection_check_boxes_input_test.rb
@@ -213,37 +213,35 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
swap SimpleForm, boolean_style: :nested do
with_input_for @user, :active, :check_boxes
- assert_select 'label.checkbox > input#user_active_true[type=checkbox]'
- assert_select 'label.checkbox', 'Yes'
- assert_select 'label.checkbox > input#user_active_false[type=checkbox]'
- assert_select 'label.checkbox', 'No'
+ assert_select 'span.checkbox > label > input#user_active_true[type=checkbox]'
+ assert_select 'span.checkbox > label', 'Yes'
+ assert_select 'span.checkbox > label > input#user_active_false[type=checkbox]'
+ assert_select 'span.checkbox > label', 'No'
assert_no_select 'label.collection_radio_buttons'
end
end
- test 'input check boxes with nested style overrides configured item wrapper tag, forcing the :label' do
+ test 'input check boxes with nested style does not overrides configured item wrapper tag' do
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
with_input_for @user, :active, :check_boxes
- assert_select 'label.checkbox > input'
- assert_no_select 'li'
+ assert_select 'li.checkbox > label > input'
end
end
- test 'input check boxes with nested style overrides given item wrapper tag, forcing the :label' do
+ test 'input check boxes with nested style does not overrides given item wrapper tag' do
swap SimpleForm, boolean_style: :nested do
with_input_for @user, :active, :check_boxes, item_wrapper_tag: :li
- assert_select 'label.checkbox > input'
- assert_no_select 'li'
+ assert_select 'li.checkbox > label > input'
end
end
test 'input check boxes with nested style accepts giving extra wrapper classes' do
swap SimpleForm, boolean_style: :nested do
with_input_for @user, :active, :check_boxes, item_wrapper_class: "inline"
- assert_select 'label.checkbox.inline > input'
+ assert_select 'span.checkbox.inline > label > input'
end
end
@@ -260,7 +258,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
with_input_for @user, :gender, :check_boxes, collection: [:male, :female], item_wrapper_class: 'custom'
assert_no_select 'label.checkbox'
- assert_select 'label.custom'
+ assert_select 'span.custom'
end
end
end
View
22 test/inputs/collection_radio_buttons_input_test.rb
@@ -300,37 +300,35 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
swap SimpleForm, boolean_style: :nested do
with_input_for @user, :active, :radio_buttons
- assert_select 'label.radio > input#user_active_true[type=radio]'
- assert_select 'label.radio', 'Yes'
- assert_select 'label.radio > input#user_active_false[type=radio]'
- assert_select 'label.radio', 'No'
+ assert_select 'span.radio > label > input#user_active_true[type=radio]'
+ assert_select 'span.radio > label', 'Yes'
+ assert_select 'span.radio > label > input#user_active_false[type=radio]'
+ assert_select 'span.radio > label', 'No'
assert_no_select 'label.collection_radio_buttons'
end
end
- test 'input radio with nested style overrides configured item wrapper tag, forcing the :label' do
+ test 'input radio with nested style does not overrides configured item wrapper tag' do
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
with_input_for @user, :active, :radio_buttons
- assert_select 'label.radio > input'
- assert_no_select 'li'
+ assert_select 'li.radio > label > input'
end
end
- test 'input radio with nested style overrides given item wrapper tag, forcing the :label' do
+ test 'input radio with nested style does not overrides given item wrapper tag' do
swap SimpleForm, boolean_style: :nested do
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :li
- assert_select 'label.radio > input'
- assert_no_select 'li'
+ assert_select 'li.radio > label > input'
end
end
test 'input radio with nested style accepts giving extra wrapper classes' do
swap SimpleForm, boolean_style: :nested do
with_input_for @user, :active, :radio_buttons, item_wrapper_class: "inline"
- assert_select 'label.radio.inline > input'
+ assert_select 'span.radio.inline > label > input'
end
end
@@ -347,7 +345,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], item_wrapper_class: 'custom'
assert_no_select 'label.radio'
- assert_select 'label.custom'
+ assert_select 'span.custom'
end
end
end

0 comments on commit 7fa6e5f

Please sign in to comment.