【问题标题】:Custom class for label and input fields using simple_form使用 simple_form 的标签和输入字段的自定义类
【发布时间】:2016-06-19 03:12:15
【问题描述】:

我正在尝试使用 simple_form 3.0.x 和 rails 4.0.x 将自定义类添加到我的输入和标签字段。

这是我的 simple_form 配置文件。

SimpleForm.setup do |config|
  config.wrappers :vertical_form, tag: 'div', error_class: 'has-error' do |b|
    b.wrapper tag: 'div' do |ba|
      b.use :label, class: 'input-group-addon'
      b.use :input, class: 'form-control'
    end
  end

  config.default_wrapper = :vertical_form
end

这是表格

<%= simple_form_for [:manage, @exam], wrapper:  :vertical_form  do |f| %>
  <%= f.input :raw_published_at %>
<% end %>

和给定的输出

<form accept-charset="UTF-8" action="/manage/exams/7-vt-2014" class="simple_form edit_exam" id="edit_exam_7" method="post">
  <div class="string optional exam_raw_published_at">
    <label class="string optional" for="exam_raw_published_at">
      Raw published at
    </label>
    <input class="string optional" id="exam_raw_published_at" name="exam[raw_published_at]" type="text" value="04/05/2014" />
    <div>
    </div>
  </div>
  <input class="btn btn-primary" name="commit" type="submit" value="Update" />
</form>

为什么没有添加我的自定义类?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 simple-form


    【解决方案1】:

    而不是使用这个:

    <%= f.input :xxxxx, :class => "my_custom_class" %>
    

    使用这个:

    <%= f.input :xxxxx, :input_html => { :class => "my_custom_class" } %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-14
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多