1
votes

I'm trying to add a custom class to my input and label fields using simple_form 3.0.x with rails 4.0.x.

Here's my simple_form config file.

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

here is the form

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

and the given output

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

Why aren't my custom classes being added?

1

1 Answers

1
votes

Instead of using this :

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

Use this :

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