Skip to content

Commit

Permalink
Use form in html_options for collection_check_boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
3v0k4 committed May 6, 2024
1 parent f6fd15c commit eb65a9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -106,7 +106,8 @@ def render_collection_for(builder_class, &block)

def hidden_field
hidden_name = @html_options[:name] || hidden_field_name
@template_object.hidden_field_tag(hidden_name, "", id: nil)
options = { id: nil, form: @html_options[:form] }
@template_object.hidden_field_tag(hidden_name, "", options)
end

def hidden_field_name
Expand Down
7 changes: 7 additions & 0 deletions actionview/test/template/form_collections_helper_test.rb
Expand Up @@ -272,6 +272,13 @@ def with_collection_check_boxes(*args, &block)
assert_select "input[type=hidden][name='user[other_category_ids][]'][value=''][autocomplete='off']", count: 1
end

test "collection check boxes generates a hidden field using the given :form 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, {}, { form: "my_form" }

assert_select "input[type=hidden][value=''][autocomplete='off'][form='my_form']", count: 1
end

test "collection check boxes generates a hidden field with index if it was provided" do
collection = [Category.new(1, "Category 1"), Category.new(2, "Category 2")]
with_collection_check_boxes :user, :category_ids, collection, :id, :name, index: 322
Expand Down

0 comments on commit eb65a9f

Please sign in to comment.