mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
add include_hidden option to collection_check_boxes helper
This commit is contained in:
parent
094e31ce67
commit
106c988c10
3 changed files with 19 additions and 4 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
* Add `include_hidden` option to `collection_check_boxes` helper.
|
||||||
|
|
||||||
|
*Vasiliy Ermolovich*
|
||||||
|
|
||||||
* Ensure ActionView::Digestor.cache is correctly cleaned up when
|
* Ensure ActionView::Digestor.cache is correctly cleaned up when
|
||||||
combining recursive templates with ActionView::Resolver.caching = false
|
combining recursive templates with ActionView::Resolver.caching = false
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,14 @@ module ActionView
|
||||||
|
|
||||||
# Append a hidden field to make sure something will be sent back to the
|
# Append a hidden field to make sure something will be sent back to the
|
||||||
# server if all check boxes are unchecked.
|
# server if all check boxes are unchecked.
|
||||||
|
if @options.fetch(:include_hidden, true)
|
||||||
hidden_name = @html_options[:name] || "#{tag_name}[]"
|
hidden_name = @html_options[:name] || "#{tag_name}[]"
|
||||||
hidden = @template_object.hidden_field_tag(hidden_name, "", :id => nil)
|
hidden = @template_object.hidden_field_tag(hidden_name, "", :id => nil)
|
||||||
|
|
||||||
rendered_collection + hidden
|
rendered_collection + hidden
|
||||||
|
else
|
||||||
|
rendered_collection
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -186,6 +186,13 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
||||||
assert_select "input[type=hidden][name='user[other_category_ids][]'][value=]", :count => 1
|
assert_select "input[type=hidden][name='user[other_category_ids][]'][value=]", :count => 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'collection check boxes does not generate a hidden field if include_hidden option is false' do
|
||||||
|
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
|
||||||
|
with_collection_check_boxes :user, :category_ids, collection, :id, :name, include_hidden: false
|
||||||
|
|
||||||
|
assert_select "input[type=hidden][name='user[category_ids][]'][value=]", :count => 0
|
||||||
|
end
|
||||||
|
|
||||||
test 'collection check boxes accepts a collection and generate a serie of checkboxes with labels for label method' do
|
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')]
|
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
|
||||||
|
|
Loading…
Reference in a new issue