Remove default class to collection_check_boxes and

collection_radio_buttons

[Carlos Antonio da Silva + Rafael Mendonça França]
This commit is contained in:
Rafael Mendonça França 2012-02-01 20:12:52 -02:00
parent 0f23426155
commit 5d8191a263
6 changed files with 36 additions and 36 deletions

@ -13,9 +13,9 @@
collection_check_boxes :post, :author_ids, Author.all, :id, :name collection_check_boxes :post, :author_ids, Author.all, :id, :name
# Outputs something like: # Outputs something like:
<input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" /> <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" />
<label class="collection_check_boxes" for="post_author_ids_1">D. Heinemeier Hansson</label> <label for="post_author_ids_1">D. Heinemeier Hansson</label>
<input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" /> <input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" />
<label class="collection_check_boxes" for="post_author_ids_2">D. Thomas</label> <label for="post_author_ids_2">D. Thomas</label>
<input name="post[author_ids][]" type="hidden" value="" /> <input name="post[author_ids][]" type="hidden" value="" />
The label/check_box pairs can be customized with a block. The label/check_box pairs can be customized with a block.
@ -28,9 +28,9 @@
collection_radio_buttons :post, :author_id, Author.all, :id, :name collection_radio_buttons :post, :author_id, Author.all, :id, :name
# Outputs something like: # Outputs something like:
<input id="post_author_id_1" name="post[author_id]" type="radio" value="1" /> <input id="post_author_id_1" name="post[author_id]" type="radio" value="1" />
<label class="collection_radio_buttons" for="post_author_id_1">D. Heinemeier Hansson</label> <label for="post_author_id_1">D. Heinemeier Hansson</label>
<input id="post_author_id_2" name="post[author_id]" type="radio" value="2" /> <input id="post_author_id_2" name="post[author_id]" type="radio" value="2" />
<label class="collection_radio_buttons" for="post_author_id_2">D. Thomas</label> <label for="post_author_id_2">D. Thomas</label>
The label/radio_button pairs can be customized with a block. The label/radio_button pairs can be customized with a block.

@ -550,11 +550,11 @@ def time_zone_options_for_select(selected = nil, priority_zones = nil, model = :
# #
# If <tt>@post.author_id</tt> is already <tt>1</tt>, this would return: # If <tt>@post.author_id</tt> is already <tt>1</tt>, this would return:
# <input id="post_author_id_1" name="post[author_id]" type="radio" value="1" checked="checked" /> # <input id="post_author_id_1" name="post[author_id]" type="radio" value="1" checked="checked" />
# <label class="collection_radio_buttons" for="post_author_id_1">D. Heinemeier Hansson</label> # <label for="post_author_id_1">D. Heinemeier Hansson</label>
# <input id="post_author_id_2" name="post[author_id]" type="radio" value="2" /> # <input id="post_author_id_2" name="post[author_id]" type="radio" value="2" />
# <label class="collection_radio_buttons" for="post_author_id_2">D. Thomas</label> # <label for="post_author_id_2">D. Thomas</label>
# <input id="post_author_id_3" name="post[author_id]" type="radio" value="3" /> # <input id="post_author_id_3" name="post[author_id]" type="radio" value="3" />
# <label class="collection_radio_buttons" for="post_author_id_3">M. Clark</label> # <label for="post_author_id_3">M. Clark</label>
# #
# It is also possible to customize the way the elements will be shown by # It is also possible to customize the way the elements will be shown by
# giving a block to the method: # giving a block to the method:
@ -570,14 +570,14 @@ def time_zone_options_for_select(selected = nil, priority_zones = nil, model = :
# #
# The builder methods <tt>label</tt> and <tt>radio_button</tt> also accept # The builder methods <tt>label</tt> and <tt>radio_button</tt> also accept
# extra html options: # extra html options:
# collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| # collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial) do |b|
# b.label(:class => "radio_button") { b.radio_button(:class => "radio_button") } # b.label(:class => "radio_button") { b.radio_button(:class => "radio_button") }
# end # end
# #
# There are also two special methods available: <tt>text</tt> and # There are also two special methods available: <tt>text</tt> and
# <tt>value</tt>, which are the current text and value methods for the # <tt>value</tt>, which are the current text and value methods for the
# item being rendered, respectively. You can use them like this: # item being rendered, respectively. You can use them like this:
# collection_radio_buttons(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| # collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial) do |b|
# b.label(:"data-value" => b.value) { b.radio_button + b.text } # b.label(:"data-value" => b.value) { b.radio_button + b.text }
# end # end
def collection_radio_buttons(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block) def collection_radio_buttons(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
@ -612,11 +612,11 @@ def collection_radio_buttons(object, method, collection, value_method, text_meth
# #
# If <tt>@post.author_ids</tt> is already <tt>[1]</tt>, this would return: # If <tt>@post.author_ids</tt> is already <tt>[1]</tt>, this would return:
# <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" /> # <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" />
# <label class="collection_check_boxes" for="post_author_ids_1">D. Heinemeier Hansson</label> # <label for="post_author_ids_1">D. Heinemeier Hansson</label>
# <input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" /> # <input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" />
# <label class="collection_check_boxes" for="post_author_ids_2">D. Thomas</label> # <label for="post_author_ids_2">D. Thomas</label>
# <input id="post_author_ids_3" name="post[author_ids][]" type="checkbox" value="3" /> # <input id="post_author_ids_3" name="post[author_ids][]" type="checkbox" value="3" />
# <label class="collection_check_boxes" for="post_author_ids_3">M. Clark</label> # <label for="post_author_ids_3">M. Clark</label>
# <input name="post[author_ids][]" type="hidden" value="" /> # <input name="post[author_ids][]" type="hidden" value="" />
# #
# It is also possible to customize the way the elements will be shown by # It is also possible to customize the way the elements will be shown by

@ -21,7 +21,7 @@ def render
if block_given? if block_given?
yield builder yield builder
else else
builder.check_box + builder.label(:class => "collection_check_boxes") builder.check_box + builder.label
end end
end end

@ -20,7 +20,7 @@ def render
if block_given? if block_given?
yield builder yield builder
else else
builder.radio_button + builder.label(:class => "collection_radio_buttons") builder.radio_button + builder.label
end end
end end
end end

@ -27,21 +27,21 @@ def with_collection_check_boxes(*args, &block)
test 'collection radio accepts a collection and generate inputs from label method' do test 'collection radio accepts a collection and generate inputs from label method' do
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s
assert_select 'label.collection_radio_buttons[for=user_active_true]', 'true' assert_select 'label[for=user_active_true]', 'true'
assert_select 'label.collection_radio_buttons[for=user_active_false]', 'false' assert_select 'label[for=user_active_false]', 'false'
end end
test 'collection radio handles camelized collection values for labels correctly' do test 'collection radio handles camelized collection values for labels correctly' do
with_collection_radio_buttons :user, :active, ['Yes', 'No'], :to_s, :to_s with_collection_radio_buttons :user, :active, ['Yes', 'No'], :to_s, :to_s
assert_select 'label.collection_radio_buttons[for=user_active_yes]', 'Yes' assert_select 'label[for=user_active_yes]', 'Yes'
assert_select 'label.collection_radio_buttons[for=user_active_no]', 'No' assert_select 'label[for=user_active_no]', 'No'
end end
test 'colection radio should sanitize collection values for labels correctly' do test 'colection radio should sanitize collection values for labels correctly' do
with_collection_radio_buttons :user, :name, ['$0.99', '$1.99'], :to_s, :to_s with_collection_radio_buttons :user, :name, ['$0.99', '$1.99'], :to_s, :to_s
assert_select 'label.collection_radio_buttons[for=user_name_099]', '$0.99' assert_select 'label[for=user_name_099]', '$0.99'
assert_select 'label.collection_radio_buttons[for=user_name_199]', '$1.99' assert_select 'label[for=user_name_199]', '$1.99'
end end
test 'collection radio accepts checked item' do test 'collection radio accepts checked item' do
@ -132,8 +132,8 @@ def with_collection_check_boxes(*args, &block)
assert_select 'input#post_category_id_1[type=radio][value=1]' assert_select 'input#post_category_id_1[type=radio][value=1]'
assert_select 'input#post_category_id_2[type=radio][value=2]' assert_select 'input#post_category_id_2[type=radio][value=2]'
assert_select 'label.collection_radio_buttons[for=post_category_id_1]', 'Category 1' assert_select 'label[for=post_category_id_1]', 'Category 1'
assert_select 'label.collection_radio_buttons[for=post_category_id_2]', 'Category 2' assert_select 'label[for=post_category_id_2]', 'Category 2'
end end
# COLLECTION CHECK BOXES # COLLECTION CHECK BOXES
@ -156,21 +156,21 @@ def with_collection_check_boxes(*args, &block)
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
with_collection_check_boxes :user, :category_ids, collection, :id, :name with_collection_check_boxes :user, :category_ids, collection, :id, :name
assert_select 'label.collection_check_boxes[for=user_category_ids_1]', 'Category 1' assert_select 'label[for=user_category_ids_1]', 'Category 1'
assert_select 'label.collection_check_boxes[for=user_category_ids_2]', 'Category 2' assert_select 'label[for=user_category_ids_2]', 'Category 2'
end end
test 'collection check boxes handles camelized collection values for labels correctly' do test 'collection check boxes handles camelized collection values for labels correctly' do
with_collection_check_boxes :user, :active, ['Yes', 'No'], :to_s, :to_s with_collection_check_boxes :user, :active, ['Yes', 'No'], :to_s, :to_s
assert_select 'label.collection_check_boxes[for=user_active_yes]', 'Yes' assert_select 'label[for=user_active_yes]', 'Yes'
assert_select 'label.collection_check_boxes[for=user_active_no]', 'No' assert_select 'label[for=user_active_no]', 'No'
end end
test 'colection check box should sanitize collection values for labels correctly' do test 'colection check box should sanitize collection values for labels correctly' do
with_collection_check_boxes :user, :name, ['$0.99', '$1.99'], :to_s, :to_s with_collection_check_boxes :user, :name, ['$0.99', '$1.99'], :to_s, :to_s
assert_select 'label.collection_check_boxes[for=user_name_099]', '$0.99' assert_select 'label[for=user_name_099]', '$0.99'
assert_select 'label.collection_check_boxes[for=user_name_199]', '$1.99' assert_select 'label[for=user_name_199]', '$1.99'
end end
test 'collection check boxes accepts selected values as :checked option' do test 'collection check boxes accepts selected values as :checked option' do
@ -248,8 +248,8 @@ def with_collection_check_boxes(*args, &block)
assert_select 'input#post_category_ids_1[type=checkbox][value=1]' assert_select 'input#post_category_ids_1[type=checkbox][value=1]'
assert_select 'input#post_category_ids_2[type=checkbox][value=2]' assert_select 'input#post_category_ids_2[type=checkbox][value=2]'
assert_select 'label.collection_check_boxes[for=post_category_ids_1]', 'Category 1' assert_select 'label[for=post_category_ids_1]', 'Category 1'
assert_select 'label.collection_check_boxes[for=post_category_ids_2]', 'Category 2' assert_select 'label[for=post_category_ids_2]', 'Category 2'
end end
test 'collection check boxes does not wrap input inside the label' do test 'collection check boxes does not wrap input inside the label' do

@ -1153,11 +1153,11 @@ If <tt>@post.author_id</tt> is 1, this would return:
<html> <html>
<input id="post_author_id_1" name="post[author_id]" type="radio" value="1" checked="checked" /> <input id="post_author_id_1" name="post[author_id]" type="radio" value="1" checked="checked" />
<label class="collection_radio_buttons" for="post_author_id_1">D. Heinemeier Hansson</label> <label for="post_author_id_1">D. Heinemeier Hansson</label>
<input id="post_author_id_2" name="post[author_id]" type="radio" value="2" /> <input id="post_author_id_2" name="post[author_id]" type="radio" value="2" />
<label class="collection_radio_buttons" for="post_author_id_2">D. Thomas</label> <label for="post_author_id_2">D. Thomas</label>
<input id="post_author_id_3" name="post[author_id]" type="radio" value="3" /> <input id="post_author_id_3" name="post[author_id]" type="radio" value="3" />
<label class="collection_radio_buttons" for="post_author_id_3">M. Clark</label> <label for="post_author_id_3">M. Clark</label>
</html> </html>
h5. collection_check_boxes h5. collection_check_boxes
@ -1189,11 +1189,11 @@ If <tt>@post.author_ids</tt> is [1], this would return:
<html> <html>
<input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" /> <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" />
<label class="collection_check_boxes" for="post_author_ids_1">D. Heinemeier Hansson</label> <label for="post_author_ids_1">D. Heinemeier Hansson</label>
<input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" /> <input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" />
<label class="collection_check_boxes" for="post_author_ids_2">D. Thomas</label> <label for="post_author_ids_2">D. Thomas</label>
<input id="post_author_ids_3" name="post[author_ids][]" type="checkbox" value="3" /> <input id="post_author_ids_3" name="post[author_ids][]" type="checkbox" value="3" />
<label class="collection_check_boxes" for="post_author_ids_3">M. Clark</label> <label for="post_author_ids_3">M. Clark</label>
<input name="post[author_ids][]" type="hidden" value="" /> <input name="post[author_ids][]" type="hidden" value="" />
</html> </html>