Permalink
Browse files

Change rendering of collection items

Put the input element of every item of radio and check box collections
inside the corresponding label.
  • Loading branch information...
1 parent ee55763 commit 17e83b5c45c37467280cc5caf26ec041c58021e4 @mfila committed Oct 6, 2011
Showing with 18 additions and 18 deletions.
  1. +6 −4 lib/simple_form/action_view_extensions/builder.rb
  2. +12 −14 test/action_view_extensions/builder_test.rb
@@ -39,8 +39,9 @@ def collection_radio(attribute, collection, value_method, text_method, options={
render_collection(
attribute, collection, value_method, text_method, options, html_options
) do |value, text, default_html_options|
- radio_button(attribute, value, default_html_options) +
- label(sanitize_attribute_name(attribute, value), text, :class => "collection_radio")
+ label(sanitize_attribute_name(attribute, value), :class => "collection_radio") do
+ radio_button(attribute, value, default_html_options) + text
+ end
end
end
@@ -83,8 +84,9 @@ def collection_check_boxes(attribute, collection, value_method, text_method, opt
) do |value, text, default_html_options|
default_html_options[:multiple] = true
- check_box(attribute, default_html_options, value, '') +
- label(sanitize_attribute_name(attribute, value), text, :class => "collection_check_boxes")
+ label(sanitize_attribute_name(attribute, value), :class => "collection_check_boxes") do
+ check_box(attribute, default_html_options, value, '') + text
@mfila

mfila Oct 7, 2011

Owner

Putting check_box here prodoces invalid HTML, reverted commit in cd3d3cbe0f1efb63ecf7b2b19db65a5581ee92a2

+ end
end
end
@@ -153,14 +153,13 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test 'collection radio wrap items in a span tag by default' do
with_collection_radio @user, :active, [true, false], :to_s, :to_s
- assert_select 'form span input[type=radio][value=true]#user_active_true + label'
- assert_select 'form span input[type=radio][value=false]#user_active_false + label'
+ assert_select 'form span label > input[type=radio][value=true]#user_active_true'
+ assert_select 'form span label > input[type=radio][value=false]#user_active_false'
end
- test 'collection radio does not wrap input inside the label' do
+ test 'collection radio wraps input inside the label' do
with_collection_radio @user, :active, [true, false], :to_s, :to_s
-
- assert_no_select 'form label input'
+ assert_select 'form label > input'
end
# COLLECTION CHECK BOX
@@ -281,8 +280,8 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test 'collection check box does not wrap the collection in the explicitly false collection wrapper tag' do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false, :item_wrapper_tag => false
- assert_select 'form > input[type=checkbox][value=true]#user_active_true'
- assert_select 'form > input[type=checkbox][value=false]#user_active_false'
+ assert_select 'form > label > input[type=checkbox][value=true]#user_active_true'
+ assert_select 'form > label > input[type=checkbox][value=false]#user_active_false'
end
test 'collection check box does not wrap the collection by default' do
@@ -310,21 +309,20 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
test 'collection check box does not wrapp each label/radio in the explicitly false item wrapper tag' do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
- assert_select 'form > input[type=checkbox][value=true]#user_active_true'
- assert_select 'form > input[type=checkbox][value=false]#user_active_false'
+ assert_select 'form > label > input[type=checkbox][value=true]#user_active_true'
+ assert_select 'form > label > input[type=checkbox][value=false]#user_active_false'
end
test 'collection check box wrap items in a span tag by default' do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
- assert_select 'form span input[type=checkbox][value=true]#user_active_true + label'
- assert_select 'form span input[type=checkbox][value=false]#user_active_false + label'
+ assert_select 'form span label > input[type=checkbox][value=true]#user_active_true'
+ assert_select 'form span label > input[type=checkbox][value=false]#user_active_false'
end
- test 'collection check box does not wrap input inside the label' do
+ test 'collection check box wraps input inside the label' do
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
-
- assert_no_select 'form label input'
+ assert_select 'form label > input'
end
# SIMPLE FIELDS

0 comments on commit 17e83b5

Please sign in to comment.