Reputation: 149
I'm trying to figure out how to hide a nested_form on my page. I know how to do hidden fields, but I know that also takes up space on the page still. How would I get it so that the whole form is hidden, and doesn't take up any space?
Form:
<%= nested_form_for @game do |f| %>
<%= f.fields_for :moves do |move_form| %>
<div id="table" data-current-player="<%=session[:current_player] %>">
<%= move_form.hidden_field :position %><br>
<%= move_form.hidden_field :player, data: {position: move_form.object.position} %>
<%= move_form.hidden_field :id %>
</div>
<% end %>
<input type="Submit" style="visibility: hidden">
<% end %>
Upvotes: 0
Views: 253
Reputation: 8065
f.fields_for
is consuming space because you have written break <br>
inside it. Even though hidden fields doesn't consume space, f.fields_for
can since it iterates for every associated element(in your case every move
object).
So in nutshell,
remove <br>
, css properties for table
if any which can result in space allocation like margin, padding
.
As well use style="display: none"
over style="visibility: hidden"
since it can consume space (check CSS Properties: Display vs. Visibility)
Upvotes: 1