Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collection_check_boxes hidden field ignores :form option #51606

Open
stimlocy opened this issue Apr 19, 2024 · 0 comments · May be fixed by #51746
Open

collection_check_boxes hidden field ignores :form option #51606

stimlocy opened this issue Apr 19, 2024 · 0 comments · May be fixed by #51746

Comments

@stimlocy
Copy link

hidden field generated from collection_check_boxes ignores form: as html_options

Steps to reproduce

<%= form_with(url: parents_url, scope: :search, method: :get, id: 'myform') do |f| %>
  <%= f.search_field :name %>
  <%= f.submit %>
<% end %>

<%= collection_check_boxes :search, :parent_ids, Parent.all, :id, :name, {}, {form: 'myform'} %>

Expected behavior

<form id="myform" action="http://localhost:3000/parents" accept-charset="UTF-8" method="get">
  <input type="search" name="search[name]" id="search_name">
  <input type="submit" name="commit" value="Save Search" data-disable-with="Save Search">
</form>

<input form="myform" type="hidden" name="search[parent_ids][]" value="" autocomplete="off">
<input form="myform" type="checkbox" value="1" name="search[parent_ids][]" id="search_parent_ids_1">
<label for="search_parent_ids_1">Parent_1</label>

Actual behavior

<form id="myform" action="http://localhost:3000/parents" accept-charset="UTF-8" method="get">
  <input type="search" name="search[name]" id="search_name">
  <input type="submit" name="commit" value="Save Search" data-disable-with="Save Search">
</form>

<input type="hidden" name="search[parent_ids][]" value="" autocomplete="off">  <!-- not exist form="myform" -->
<input form="myform" type="checkbox" value="1" name="search[parent_ids][]" id="search_parent_ids_1">
<label for="search_parent_ids_1">Parent_1</label>

Probably the same problem as #12344

System configuration

Rails version: 7.1.3.2
Ruby version: 3.3.0

Using collection_check_boxes inside a form is fine, but if you want to use them outside of a form, it is convenient to be able to use the :form option.
For now, I am using include_hidden: false and <%= hidden_field_tag 'search[parent_ids][]', {}, form: 'myform' %> to work around the problem.

Let me know if there's any additional information needed.

3v0k4 added a commit to 3v0k4/rails that referenced this issue May 6, 2024
3v0k4 added a commit to 3v0k4/rails that referenced this issue May 6, 2024
3v0k4 added a commit to 3v0k4/rails that referenced this issue May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants