Omn*_*ent 31 ruby-on-rails formtastic simple-form
使用simple_form我们可以使用以下方法更改标签的类:
label_html => {:class => "myclass"}
但在处理复选框时我们如何做同样的事情呢?
simple_form 指定默认类 collection_check_boxes
有没有办法更改此默认类?
fly*_*ish 65
我想对这个答案进行更新,以防有人来这里寻找方法来做到这一点.
您可以使用此选项为标签指定一个类 :item_wrapper_class => 'class_goes_here'
这是一个完整的例子:
= user.input :resident,
:collection => [["In the U.S", true],["Outside the U.S.", false]],
:label_method => :first,
:value_method => :last,
:as => :radio_buttons,
:label => "Where is your principle residence?",
:item_wrapper_class => 'inline'
Run Code Online (Sandbox Code Playgroud)
如果你想要你可以传递new_class给标签做类似的事情:
<%= f.collection_check_boxes attribute, collection, value_method, text_method do |b|
b.label(class: 'new_class') {b.check_box + b.text}
end %>
Run Code Online (Sandbox Code Playgroud)
您应该能够在表单输入上设置 :input_html 。
像这样的东西:
f.input :something, :as => :check_box, :input_html => { :class => "myclass" }
Run Code Online (Sandbox Code Playgroud)
伊恩。
| 归档时间: |
|
| 查看次数: |
21638 次 |
| 最近记录: |