1
votes

So I am using the bootstrap-sass and simple_form gem and ran the installer with --boostrap which means it generated the simple_form_bootstrap.rb in the config/initializers/ directory.

I am trying to use the class form-horizontal from bootstrap but this requires wrapping the input with a div that has the class col-xx-xx.

I looked in the aforementioned initializer and saw this block:

 config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.optional :maxlength
    b.optional :pattern
    b.optional :min_max
    b.optional :readonly
    b.use :label, class: 'col-sm-3 control-label'

    b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
      ba.use :input, class: 'form-control'
      ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
      ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
    end
  end

Which seems like the initializer would already apply the right class to the label and wrap the input tag in a div. However this is not the case. Is there an error in the initializer?

For reference this is the form:

<%= simple_form_for @article, remote: true, html: {class: "form-horizontal"} do |f| %>
        <ul class="errors"></ul>
            <%= f.input :author%>
            <%= f.input :title%>
            <%= f.button :submit, class: "btn btn-primary" %>
<% end %>

and this the corresponding html:

<div class="form-group string optional article_author">
  <label class="string optional control-label" for="article_author">...</label>
  <input id="article_author" class="string optional form-control" type=".." name=".." value="..." style="..."></input>
</div>

so it seems like some of the stuff from the initializer gets added like the class form-control but not the rest. Why?

1

1 Answers

1
votes

So turns out you need to apply the wrapper in the form_for tag with wrapper: "form_horizontal". That will use all the initializers for that name.