Wrap collections items in a div, not in the label.
Label and input are now on the same level.
This commit is contained in:
parent
8ca428dda9
commit
4b216eb62c
|
@ -61,7 +61,7 @@ module SimpleForm
|
|||
|
||||
# You can wrap each item in a collection of radio/check boxes with a tag, defaulting to none.
|
||||
mattr_accessor :item_wrapper_tag
|
||||
@@item_wrapper_tag = nil
|
||||
@@item_wrapper_tag = :div
|
||||
|
||||
# You can wrap all inputs in a pre-defined tag. Default is a div.
|
||||
mattr_accessor :wrapper_tag
|
||||
|
|
|
@ -39,8 +39,8 @@ module SimpleForm
|
|||
render_collection(
|
||||
attribute, collection, value_method, text_method, options, html_options
|
||||
) do |value, text, default_html_options|
|
||||
radio = radio_button(attribute, value, default_html_options)
|
||||
collection_label(attribute, value, radio, text, :class => "collection_radio")
|
||||
radio_button(attribute, value, default_html_options) +
|
||||
label(sanitize_attribute_name(attribute, value), text, :class => "collection_radio")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -83,8 +83,8 @@ module SimpleForm
|
|||
) do |value, text, default_html_options|
|
||||
default_html_options[:multiple] = true
|
||||
|
||||
check_box = check_box(attribute, default_html_options, value, '')
|
||||
collection_label(attribute, value, check_box, text, :class => "collection_check_boxes")
|
||||
check_box(attribute, default_html_options, value, '') +
|
||||
label(sanitize_attribute_name(attribute, value), text, :class => "collection_check_boxes")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -109,11 +109,6 @@ module SimpleForm
|
|||
|
||||
private
|
||||
|
||||
# Wraps the given component in a label, for better accessibility with collections.
|
||||
def collection_label(attribute, value, component_tag, label_text, html_options) #:nodoc:
|
||||
label(sanitize_attribute_name(attribute, value), component_tag << label_text.to_s, html_options)
|
||||
end
|
||||
|
||||
# Generate default options for collection helpers, such as :checked and
|
||||
# :disabled.
|
||||
def default_html_options_for_collection(item, value, options, html_options) #:nodoc:
|
||||
|
|
|
@ -118,10 +118,17 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form li input[type=radio][value=false]#user_active_false'
|
||||
end
|
||||
|
||||
test 'collection radio does not wrap items by default' do
|
||||
test 'collection radio wrap items in a div tag by default' do
|
||||
with_collection_radio @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_no_select 'form li'
|
||||
assert_select 'form div input[type=radio][value=true]#user_active_true + label'
|
||||
assert_select 'form div input[type=radio][value=false]#user_active_false + label'
|
||||
end
|
||||
|
||||
test 'collection radio does not wrap input inside the label' do
|
||||
with_collection_radio @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_no_select 'form label input[type=radio][value=true]#user_active_true'
|
||||
end
|
||||
|
||||
# COLLECTION CHECK BOX
|
||||
|
@ -239,7 +246,7 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form ul input[type=checkbox][value=false]#user_active_false'
|
||||
end
|
||||
|
||||
test 'collection check box does not wrap the collection by default' do
|
||||
test 'collection check box wrap the collection by default' do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_no_select 'form ul'
|
||||
|
@ -261,10 +268,17 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form li input[type=checkbox][value=false]#user_active_false'
|
||||
end
|
||||
|
||||
test 'collection check box does not wrap items by default' do
|
||||
test 'collection check box wrap items in a div by default' do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_no_select 'form li'
|
||||
assert_select 'form div input[type=checkbox][value=true]#user_active_true + label'
|
||||
assert_select 'form div input[type=checkbox][value=false]#user_active_false + label'
|
||||
end
|
||||
|
||||
test 'collection check box does not wrap input inside the label' do
|
||||
with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
|
||||
|
||||
assert_no_select 'form label input[type=checkbox][value=true]#user_active_truel'
|
||||
end
|
||||
|
||||
# SIMPLE FIELDS
|
||||
|
|
Loading…
Reference in New Issue