0

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 %>
5
  • That sure isn't HTML. Please post the corresponding HTML. Commented Sep 29, 2014 at 16:40
  • try style="display:none;" Commented Sep 29, 2014 at 17:08
  • Where would I put that? Typically, when I try to insert something into the first line, it comes up with an error. Commented Sep 29, 2014 at 17:09
  • try: <input type="Submit" style="display:none;"> because that's the only thing visible, right? Commented Sep 29, 2014 at 19:06
  • That's what I ended up doing, I was just trying to figure out how to make the whole form hidden, so I didn't have all of that hidden_field hanging out there. Commented Sep 29, 2014 at 19:08

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

2 Comments

How do I set an id or class within the nested_form tag so that I can use css?
you should be able to do so with passing :class => "some class" or :html_options => {:class => "some class" }. I have not tested it, but should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.