diff options
author | Vasiliy Ermolovich <younash@gmail.com> | 2013-10-27 18:14:16 +0300 |
---|---|---|
committer | Vasiliy Ermolovich <younash@gmail.com> | 2013-10-27 18:31:19 +0300 |
commit | 106c988c10c29332343d8de5719a8b045d093753 (patch) | |
tree | 8b0083253b0af4282036b9136dc587bcfd3cf3d9 /actionview | |
parent | 094e31ce6700993759c6f36db52afb0a43bfa71f (diff) | |
download | rails-106c988c10c29332343d8de5719a8b045d093753.tar.gz rails-106c988c10c29332343d8de5719a8b045d093753.tar.bz2 rails-106c988c10c29332343d8de5719a8b045d093753.zip |
add include_hidden option to collection_check_boxes helper
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/CHANGELOG.md | 6 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/tags/collection_check_boxes.rb | 10 | ||||
-rw-r--r-- | actionview/test/template/form_collections_helper_test.rb | 7 |
3 files changed, 19 insertions, 4 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 59b803d088..959509510e 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,6 +1,10 @@ +* Add `include_hidden` option to `collection_check_boxes` helper. + + *Vasiliy Ermolovich* + * Ensure ActionView::Digestor.cache is correctly cleaned up when combining recursive templates with ActionView::Resolver.caching = false - + *wyaeld* * Fix `collection_check_boxes` generated hidden input to use the name attribute provided diff --git a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb index 9b77ebeb1b..8b28e4fc33 100644 --- a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb +++ b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb @@ -27,10 +27,14 @@ module ActionView # Append a hidden field to make sure something will be sent back to the # server if all check boxes are unchecked. - hidden_name = @html_options[:name] || "#{tag_name}[]" - hidden = @template_object.hidden_field_tag(hidden_name, "", :id => nil) + if @options.fetch(:include_hidden, true) + hidden_name = @html_options[:name] || "#{tag_name}[]" + hidden = @template_object.hidden_field_tag(hidden_name, "", :id => nil) - rendered_collection + hidden + rendered_collection + hidden + else + rendered_collection + end end private diff --git a/actionview/test/template/form_collections_helper_test.rb b/actionview/test/template/form_collections_helper_test.rb index d28e4aeb48..4e9cd74df5 100644 --- a/actionview/test/template/form_collections_helper_test.rb +++ b/actionview/test/template/form_collections_helper_test.rb @@ -186,6 +186,13 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select "input[type=hidden][name='user[other_category_ids][]'][value=]", :count => 1 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 collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] with_collection_check_boxes :user, :category_ids, collection, :id, :name |