简体   繁体   中英

Hide input simple_form, Ruby on Rails

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();

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' }

在简单表单上,如果你需要将输入字段设为隐藏使用这些代码<%= f.input:s_n,:as =>:hidden%>我认为它比使用jquery代码更好

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM