2

I've got a form where some text fields should be visible only under certain conditions. Basically, there's a select list and depending on what's selected, other fields are either showing or not. So by default I need to hide divs that wrap inputs in the form generated by simple_form gem.

Example:

= simple_form_for
  = f.select ...
  = f.input :s_n1, :required => true
  = f.input :s_n2, :required => true
  = f.input :s_n3, :required => true

It should behave the same as hide() by jqyuery:

$("div.s_n1").hide();
$("div.s_n2").hide();
$("div.s_n3").hide();
2
  • 1
    As it stands, the question is a bit vague, could you elaborate on what problems you're having while trying to hide the input? Commented Mar 13, 2013 at 15:04
  • you want to have a sort of a generated field that the user doesn't need to fill in? If so, try hidden_field_tag. If not then sorry, i misunderstud :) Commented Mar 13, 2013 at 15:05

2 Answers 2

2

on simple form if you need to make input field as hidden use these code <%= f.input :s_n ,:as => :hidden%> I think its more better than using jquery code

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

2 Comments

:as => :hidden and .hide() is not the same
Yeah that's not the same, it changed input to type hidden instead
2

Use simple form wrapper_html attribute:

= simple_form_for
  = f.select ...
  = f.input :s_n1, required: true, wrapper_html: { class: 'hide' }
  = f.input :s_n2, required: true, wrapper_html: { class: 'hide' }
  = f.input :s_n3, required: true, wrapper_html: { class: 'hide' }

Comments

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.