有没有办法为简单表单集合中的选项提供单独的样式类

时间:2012-08-13 02:35:04

标签: ruby-on-rails-3 ruby-on-rails-3.1 simple-form

我有

<%= f.input :user_type, :label_html => { :class => 'option_label_name' }, :label => "User Type" ,:collection => [["Master"], ["HO Administrator"], ["Practice Manager"], ["Branch Administrator"], ["Consultant"]], :include_blank => false %>
</div>

这会创建一个包含许多选项的列表,但是我想知道是否有任何方法只为集合元素提供css样式类...

在当前形式中,样式仅提供给标签而不是选项...

我找到了一个解决方案......它不是我要找的那个,但确实有用..

<div id="innerblock_left">
<%= f.label :user_type, :class =>"label_name", :label => "User Type" %>
<select class="style2">
<option value="1">Master</option>
<option value="2">HO Administrator</option>
<option value="3">Practice Manager</option>
<option value="4">Branch Administrator</option>
<option value="5">Consultant</option>
</select>
</div>

虽然如果有人知道如何为简单的表单集合元素提供样式,那就好了......

感谢您阅读..

1 个答案:

答案 0 :(得分:0)

0只是一个简单的解决方案:

在表单助手中,定义集合:

def list
  [["Master",:class => "d_1"], ["HO Administrator",:class => "d_2"], ["Practice Manager",:class => "d_0"],["Branch Administrator",:class => "d_2"], ["Consultant",:class => "d_2"]]
end

在您的表单中:

<%= f.input :user_type, :label_html => { :class => 'option_label_name' }, :label => "User Type" ,:collection => list, :include_blank => false %>

并在资产中添加一些CSS技巧:

.d_0 {
  font-weight: bold; }
.d_1{
  font-style: italic;
  text-decoration: underline;
  padding-left: 10px;}
.d_2 {
  font-style: italic;
  padding-left: 20px;}