1

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

1

Instead of using this :

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

Use this :

<%= f.input :xxxxx, :input_html => { :class => "my_custom_class" } %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.