提交 8ae80447 编写于 作者: A Angel N. Sciortino

Use the given name in html_options for the hidden field in collection_check_boxes

上级 b1178aef
......@@ -27,7 +27,8 @@ def render(&block)
# Append a hidden field to make sure something will be sent back to the
# server if all check boxes are unchecked.
hidden = @template_object.hidden_field_tag("#{tag_name}[]", "", :id => nil)
hidden_name = @html_options[:name] || "#{tag_name}[]"
hidden = @template_object.hidden_field_tag(hidden_name, "", :id => nil)
rendered_collection + hidden
end
......
......@@ -179,6 +179,13 @@ def with_collection_check_boxes(*args, &block)
assert_select "input[type=hidden][name='user[category_ids][]'][value=]", :count => 1
end
test 'collection check boxes generates a hidden field using the given :name in :html_options' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
with_collection_check_boxes :user, :category_ids, collection, :id, :name, {}, {name: "user[other_category_ids][]"}
assert_select "input[type=hidden][name='user[other_category_ids][]'][value=]", :count => 1
end
test 'collection check boxes accepts a collection and generate a serie of checkboxes with labels for label method' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
with_collection_check_boxes :user, :category_ids, collection, :id, :name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册