I use simple_form gem in rails project and am going to implement a form. The form is very simple:
<%= simple_form_for admin, url: url do |f| %>
<div class="form-inputs">
<%= f.input :name %> #String
<%= f.input :email %> #String
<%= f.input :sso_only %> #Boolean
</div>
<% end %>
The generated html is:
<form novalidate="novalidate" class="simple_form new_user" id="new_user" action="/admin/admins" accept-charset="UTF-8" method="post">
<div class="form-group string required user_name">
<label class="string required col-sm-4 control-label" for="user_name">
<abbr title="required">*</abbr>
Name
</label>
<div class="col-sm-8">
<input class="string required form-control" type="text" name="user[name]" id="user_name">
</div>
</div>
<div class="form-group email required user_email">
<label class="email required col-sm-4 control-label" for="user_email">
<abbr title="required">*</abbr>
Email
</label>
<div class="col-sm-8">
<input class="string email required form-control" type="email" value="" name="user[email]" id="user_email">
</div>
</div>
<div class="form-group boolean optional user_sso_only">
<div class="col-sm-8">
<div class="checkbox">
<input value="0" type="hidden" name="user[sso_only]">
<label class="boolean optional" for="user_sso_only">
<input class="boolean optional" type="checkbox" value="1" name="user[sso_only]" id="user_sso_only">
SSO Only
</label>
</div>
</div>
</div>
</form>
The display is:
From the image we can see, the name and email fields include label and input two parts. label has 4 size and input has 8.
However, the checkbox only include one part, which is 8. So it is very ugly when the checkbox in that position.
Normally, I would like the checkbox starts at the same position as the input box. And that should be the normal display for a form.
Therefore, is there any way to reach this by using simple_form itself? without customise the CSS.
I have tried wrapper but failed.
To achieve the result you want, and allow customisation, you'll need to make a modification to both your markup and the wrapper.
see: https://github.com/plataformatec/simple_form#the-wrappers-api
You can modify the existing top level wrapper to expose the div for which you want to include the offset.
Your erb markup for the sso_only field can be modified like so:
<%= f.input :sso_only, checkbox_wrapper_html: { class: 'col-sm-offset-4' } %>
Then, in order for the markup to recognise the modification, you have to change your existing initializer containing your wrapper definitions to respond to the checkbox_wrapper option (taken from the defaults).
# config/initializers/simple_form.rb
....
config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.wrapper :checkbox_wrapper, tag: 'div', class: 'col-sm-8' do |wr|
wr.wrapper tag: 'div', class: 'checkbox' do |ba|
ba.use :label_input
end
wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
....
note the addition of :checkbox_wrapper within the block. This will allow you to use the checkbox_wrapper_html option in the markup as mentioned above.
This can also be applied to any other existing wrapper.
Im not familar with simple form but it looks like you need another column like your inputs. Try adding some kind of span with the 'col-sm-4' class.
<span class="col-sm-4 control-label" for=""></span>
<div class="col-sm-8">
<div class="checkbox">
<input value="0" type="hidden" name="user[sso_only]">
<label class="boolean optional" for="user_sso_only">
<input class="boolean optional" type="checkbox" value="1" name="user[sso_only]" id="user_sso_only">
SSO Only
</label>
</div>
</div>
Related
Hello I am doing my very first tests and I would need your help. I am using Rails5.
The problem is because of the nested fields I believe...(used Cocoon gem)
Capybara returns this error:
Capybara::ElementNotFound:
Unable to find field "event_participants_attributes_1489697584487_first_name"
my html looks like this:
<div class="nested-fields">
<div class="form-group string optional event_participants_first_name"><label class="control-label string optional" for="event_participants_attributes_1489697584487_first_name">Participant's first name</label><input class="form-control string optional" type="text" name="event[participants_attributes][1489697584487][first_name]" id="event_participants_attributes_1489697584487_first_name" data-com.agilebits.onepassword.user-edited="yes"></div>
<div class="form-group integer optional event_participants_salary"><label class="control-label integer optional" for="event_participants_attributes_1489697584487_salary">Participant's monthly pay</label><input class="form-control numeric integer optional" type="number" step="1" name="event[participants_attributes][1489697584487][salary]" id="event_participants_attributes_1489697584487_salary"></div>
<div class="links">
<input type="hidden" name="event[participants_attributes][1489697584487][_destroy]" id="event_participants_attributes_1489697584487__destroy" value="false"><a class="btn btn-danger btn-xs btn-remove-friend remove_fields dynamic" href="#">Remove this friend</a>
</div>
</div>
and here is my features/events/create_event.spec.rb
require 'spec_helper'
require 'rails_helper'
describe "Creating an event" do
it "redirects on result page on success" do
visit "/"
click_link "Create a new event"
expect(page).to have_content('Wanna share fair?')
fill_in :name, with: 'Rent a plane'
fill_in "What is the total price", with: 200
click_link "Add a participant"
fill_in "event_participants_attributes_1489697584487_first_name", with: "John"
enter code here
fill_in ":event_participants_attributes_1489697584487_salary", with: 2300
click_button "See result"
expect(page).to have_content('Your salary together:')
end
end
And here are my simple_forms:
_form.html.erb
<%= simple_form_for #event do |f| %>
<div class="col-xs-12 col-md-10 col-md-offset-1">
<h1>Wanna share fair?</h1>
<p>Create an event, enter the bill to share.</p>
<%= f.input :name, label: "Event's name" %>
<%= f.input :total_price, label: "What is the total price" %>
<p>Add the participants.</p>
<div id="participants">
<%= f.simple_fields_for :participants do |participant| %>
<%= render "participants_fields", f: participant %>
<% end %>
<div class="links text-center">
<%= link_to_add_association "Add a participant", f, :participants, partial: "participants_fields", class:"btn btn-primary btn-sm btn-add-friend" %>
</div>
</div>
</div>
<div class="col-xs-12 col-md-10 col-md-offset-1 text-center">
<%= f.submit "See result" , class:"btn btn-success btn-lg btn-event" %>
</div>
<% end %>
_participants_fields.html.erb
<div class="nested-fields">
<%= f.input :first_name, label: "Participant's first name" %>
<%= f.input :salary, label: "Participant's monthly pay" %>
<div class="links">
<%= link_to_remove_association "Remove this friend", f , class: "btn btn-danger btn-xs btn-remove-friend" %>
</div>
</div>
edit more html
<form novalidate="novalidate" class="simple_form new_event" id="new_event" action="/events" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="O5XM0JMiVBbpPNaKF1apw7rdtC/XEBhasZQoK6POycZQ2Zp14Td1ljoJyIUKTwtl91LlBHeDkKFtcWRnNu+iEQ==">
<div class="col-xs-12 col-md-10 col-md-offset-1">
<h1>Wanna share fair?</h1>
<p>Create an event, enter the bill to share.</p>
<div class="form-group string optional event_name"><label class="control-label string optional" for="event_name">Event's name</label><input class="form-control string optional" type="text" name="event[name]" id="event_name" data-com.agilebits.onepassword.user-edited="yes"></div>
<div class="form-group integer optional event_total_price"><label class="control-label integer optional" for="event_total_price">What is the total price</label><input class="form-control numeric integer optional" type="number" step="1" name="event[total_price]" id="event_total_price" data-com.agilebits.onepassword.user-edited="yes"></div>
<p>Add the participants.</p>
<div id="participants">
<div class="nested-fields">
<div class="form-group string optional event_participants_first_name"><label class="control-label string optional" for="event_participants_attributes_1489705438668_first_name">Participant's first name</label><input class="form-control string optional" type="text" name="event[participants_attributes][1489705438668][first_name]" id="event_participants_attributes_1489705438668_first_name" data-com.agilebits.onepassword.user-edited="yes"></div>
<div class="form-group integer optional event_participants_salary"><label class="control-label integer optional" for="event_participants_attributes_1489705438668_salary">Participant's monthly pay</label><input class="form-control numeric integer optional" type="number" step="1" name="event[participants_attributes][1489705438668][salary]" id="event_participants_attributes_1489705438668_salary" data-com.agilebits.onepassword.user-edited="yes"></div>
<div class="links">
<input type="hidden" name="event[participants_attributes][1489705438668][_destroy]" id="event_participants_attributes_1489705438668__destroy" value="false"><a class="btn btn-danger btn-xs btn-remove-friend remove_fields dynamic" href="#">Remove this friend</a>
</div>
</div><div class="nested-fields">
<div class="form-group string optional event_participants_first_name"><label class="control-label string optional" for="event_participants_attributes_1489705443842_first_name">Participant's first name</label><input class="form-control string optional" type="text" name="event[participants_attributes][1489705443842][first_name]" id="event_participants_attributes_1489705443842_first_name" data-com.agilebits.onepassword.user-edited="yes"></div>
<div class="form-group integer optional event_participants_salary"><label class="control-label integer optional" for="event_participants_attributes_1489705443842_salary">Participant's monthly pay</label><input class="form-control numeric integer optional" type="number" step="1" name="event[participants_attributes][1489705443842][salary]" id="event_participants_attributes_1489705443842_salary" data-com.agilebits.onepassword.user-edited="yes"></div>
<div class="links">
<input type="hidden" name="event[participants_attributes][1489705443842][_destroy]" id="event_participants_attributes_1489705443842__destroy" value="false"><a class="btn btn-danger btn-xs btn-remove-friend remove_fields dynamic" href="#">Remove this friend</a>
</div>
</div><div class="links text-center">
<a class="btn btn-primary btn-sm btn-add-friend add_fields" data-association="participant" data-associations="participants" data-association-insertion-template="<div class="nested-fields">
<div class="form-group string optional event_participants_first_name"><label class="control-label string optional" for="event_participants_attributes_new_participants_first_name">Participant's first name</label><input class="form-control string optional" type="text" name="event[participants_attributes][new_participants][first_name]" id="event_participants_attributes_new_participants_first_name" /></div>
<div class="form-group integer optional event_participants_salary"><label class="control-label integer optional" for="event_participants_attributes_new_participants_salary">Participant's monthly pay</label><input class="form-control numeric integer optional" type="number" step="1" name="event[participants_attributes][new_participants][salary]" id="event_participants_attributes_new_participants_salary" /></div>
<div class="links">
<input type="hidden" name="event[participants_attributes][new_participants][_destroy]" id="event_participants_attributes_new_participants__destroy" value="false" /><a class="btn btn-danger btn-xs btn-remove-friend remove_fields dynamic" href="#">Remove this friend</a>
</div>
</div>
" href="#">Add a participant</a>
</div>
</div>
</div>
<div class="col-xs-12 col-md-10 col-md-offset-1 text-center">
<input type="submit" name="commit" value="See result" class="btn btn-success btn-lg btn-event" data-disable-with="See result">
</div>
</form>
IIRC the "1489697584487" part of the ids you show is created by Cocoon based on the current timestamp. That means every time you run your test the number will be different so you're not going to be able to select those elements by id.
Instead if you're only adding one participant you should be able to do something like
fill_in "Participant's first name", with: "John"
fill_in "Participant's monthly pay", with: "2300"
If you are adding multiple participants then depending on the exact layout you can use nth-child/nth-of-type CSS selectors to scope the fill_in or use all and select the one you want, etc.
find('.nested-fields:nth-child(2)').fill_in ...
all(:field, "Participant's first name", minimum: 2)[1].set("John") # 0 based index so minimum should be 1 more than the index you want
Also - For any of this to work you need to be using a JS capable driver (Cocoon requires JS). You haven't tagged your spec with js: true metadata so either you've overridden the default driver, or you're not currently using a JS capable driver - see https://github.com/teamcapybara/capybara#selecting-the-driver. Also see https://github.com/teamcapybara/capybara#transactions-and-database-setup and https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example if you haven't yet configure database_cleaner for use with JS capable drivers
Is it possible to have the checkbox labels on the left like the others, and the checkbox on the right like the other inputs with a horizontal form?
My current setup
It looks pretty awful.
EDIT:
<%= simple_form_for :apartment, :html => {:multipart => true, :class => 'form-horizontal'}, wrapper: :horizontal_form do |f| %>
<%= f.input :pets, as: :boolean, label: 'Husdyr tilladt' %>
<% end %>
which generates the following html in the view:
<div class="form-group boolean optional apartment_pets">
<div class="checkbox"><input value="0" type="hidden" name="apartment[pets]">
<label class="boolean optional" for="apartment_pets"><input class="boolean optional" type="checkbox" value="1" name="apartment[pets]" id="apartment_pets">
Husdyr tilladt
</label>
</div>
</div>
You can add pull-right to the class of your checkbox element like so:
<input name="uh" id="uhhuh" type="checkbox" class="pull-right" />
Updated answer with user provided code:
<div class="form-group boolean optional apartment_pets">
<div class="checkbox"><input value="0" type="hidden" name="apartment[pets]">
<label class="boolean optional" for="apartment_pets">Husdyr tilladt</label>
<input class="boolean optional" type="checkbox" value="1" name="apartment[pets]" id="apartment_pets" class="pull-right">
</div>
</div>
I never used simple_form but from browsing the documentation, it looks like you should use a combination of :label => false and :inline_label => true to position your label.
I am trying to make custom wrapper for a hybrid form like this:
The idea here is that there are the radio buttons that enable either the date picker, occurrences or indefinite. I currently have these manually created and I am trying to make a custom Simple Form wrapper to avoid all the hassle of adding tons of code to a simple input. The second occurrence input is the one that I can't get quite right. Here is the HTML for the form shown:
<div class="form-group radio_buttons required work_order_end_task">
<label class="radio_buttons required col-sm-2 control-label"><i class="fa fa-check-circle text-danger"></i> End Date</label>
<div class="col-sm-2">
<div class="input-group">
<span class="input-group-addon border-none">
<input class="radio_buttons required" type="radio" value="date" name="work_order[end_task]" id="work_order_end_task_date">
</span>
<input disabled="" type="text" value="" name="work_order[end_date]" id="work_order_end_date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-date-clear-btn="true" data-date-today-btn="linked" data-date-orientation="auto right" data-date-today-highlight="true" class="date required form-control left-border-rounded">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
</div>
<br>
<div class="input-group">
<span class="input-group-addon border-none">
<input class="radio_buttons required" type="radio" value="number" name="work_order[end_task]" id="work_order_end_task_number">
</span>
<input class="numeric integer form-control" type="string" value="" name="work_order[count]" id="work_order_count">
<span class="input-group-addon">
Occurrence(s)
</span>
</div>
<br>
<div class="input-group integer optional work_order_count">
<span class="input-group-addon border-none radio_buttons optional work_order_end_task">
<span class="radio">
<label for="work_order_end_task_none">
<input class="radio_buttons optional radio_buttons" type="radio" value="none" checked="checked" name="work_order[end_task]" id="work_order_end_task_none">
</label>
</span>
</span>
<input class="string optional form-control" type="text" value="" name="work_order[count]" id="work_order_count">
<span class="input-group-addon">Occurrence(s)</span>
</div>
<br>
<div class="form-group radio_buttons optional work_order_end_task"><div class="col-sm-10"><span class="radio"><label class="static-radio" for="work_order_end_task_none"><input class="radio_buttons optional" type="radio" value="none" checked="checked" name="work_order[end_task]" id="work_order_end_task_none">Indefinite</label></span></div></div>
</div>
</div>
The issue is all the extra spans and labels being added. Here is my code:
<%= f.input :count, wrapper: :input_group do %>
<%= f.input :end_task, as: :radio_buttons, wrapper: :radio_addon, collection: [['','none']], label: false %>
<%= f.input_field :count, as: :string, class: "form-control" %>
<span class="input-group-addon">Occurrence(s)</span>
<% end %>
and wrappers:
config.wrappers :input_group, tag: 'div', class: 'input-group', error_class: 'has-error' do |b|
b.use :html5
b.use :input, class: 'form-control'
end
config.wrappers :radio_addon, tag: 'span', class: 'input-group-addon border-none' do |b|
b.use :html5
b.optional :readonly
b.use :input, class: 'radio_buttons'
end
So how do I get rid of the <span class="radio">
and <label for="work_order_end_task_none"> on the radio buttons and then all the extra classes ( integer optional work_order_count for example) being inserted into the wrappers and inputs?
I think I figured this out (sort of):
<span class="input-group-addon border-none">
<%= f.radio_button :end_task, 'number', label: false %>
</span>
Works like a charm. I would still like to add a custom wrapper to this to avoid having to manually add the wrapper span but that does not seem to work.
Using Rails 4, Simple_Form and Bootstrap 3, I am trying to get my output HTML look like this to work with some front end styling:
<div class="checkbox">
<input value="0" type="hidden" name="member[remember_me]">
<label class="boolean optional" for="member_remember_me">
<input type="checkbox" value="">
<i class="input-helper"></i>
Keep me signed in
</label>
</div>
In my form, I have this:
<%= f.input :remember_me, class: 'checkbox inline', type: 'checkbox', as: :boolean if devise_mapping.rememberable? %>
And I cannot figure out how to get the image tag to show up inside the input field. What I get when the form is generated is this (missing the image tag):
<div class="checkbox">
<input value="0" type="hidden" name="member[remember_me]">
<label class="boolean optional" for="member_remember_me">
<input class="boolean optional" type="checkbox" value="1" name="member[remember_me]" id="member_remember_me">Remember me
</label>
</div>
I've tried this block that I thought should do it, but alas, no:
<%= f.input :remember_me, class: 'checkbox inline', type: 'checkbox', as: :boolean if devise_mapping.rememberable? do %>
<i class="input-helper"></i>
<% end %>
Any suggestions? Do I need to write a custom wrapper to get the image tag to show?
One option to put content inside any rails tag is to use
"#{image_tag('filename.png')}".html_safe
in place of the text, or using raw().
I have two rails apps, and the 'form-horizontal' is working in one, but not the other, and I have no idea why.
First app is called "Horizontal" (my test app) and the other is "Inventory"
Form in "horizontal" app:
<%= simple_form_for(#part, html: {class: 'form-horizontal' }) do |f| %>
<div class="field">
<%= f.input :name %>
</div>
<div class="field">
<%= f.input :number %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
and looks like this in the browser:
and the form for the "inventory" app is:
<%= simple_form_for(#item, html: {class: 'form-horizontal' }) do |f| %>
<%= f.error_notification %>
<div class="field">
<%= f.input :part_number %>
</div>
<div class="field">
<%= f.input :on_order_qty %>
<%= f.input :revision %>
<%= f.input :current_rev %>
<%= f.input :name, required: false%><br>
</div>
<%= f.simple_fields_for :parts do |part| %>
<%= render 'part_fields', :f => part %>
<% end %>
<div class="links">
<%= link_to_add_association 'Add additional supplier', f, :parts %><br><br>
</div>
<div class="fields">
<%= f.input :stock_qty %>
<%= f.input :ncmr_qty %>
</div>
<div class="form-actions">
<%= f.submit %>
</div>
<% end %>
but it looks like this in the browser:
Why won't the form-horizontal class work in the "Inventory" app?
It appears that the integer input fields are getting rendered horizontally, but something weird is happening in the text input fields. Here is the source html from the browser for the "Inventory" app:
<form accept-charset="UTF-8" action="/items" class="simple_form form-horizontal"
id="new_item" method="post"><div style="margin:0;padding:0;display:inline"><input
name="utf8" type="hidden" value="✓" /><input name="authenticity_token"
type="hidden" value="H3DKGhGdtfv1e8F1rg9TgDJUyaBspXOSFMpm2gnjwzk=" /></div>
<div class="field">
<div class="input string required item_part_number"><label class="string required"
for="item_part_number"><abbr title="required">*</abbr> Part number</label><input aria
required="true" class="string required" id="item_part_number" maxlength="255"
name="item[part_number]" required="required" size="255" type="text" /></div>
</div>
<div class="field">
<div class="input integer optional item_on_order_qty"><label class="integer optional"
for="item_on_order_qty">On order qty</label><input class="numeric integer optional"
id="item_on_order_qty" name="item[on_order_qty]" step="1" type="number" /></div>
<div class="input string optional item_revision"><label class="string optional"
for="item_revision">Revision</label><input class="string optional" id="item_revision"
maxlength="255" name="item[revision]" size="255" type="text" /></div>
<div class="input boolean optional item_current_rev"><input name="item[current_rev]"
type="hidden" value="0" /><input class="boolean optional" id="item_current_rev"
name="item[current_rev]" type="checkbox" value="1" /><label class="boolean optional"
for="item_current_rev">Current rev</label></div>
<div class="input string optional item_name"><label class="string optional"
for="item_name">Name</label><input class="string optional" id="item_name" maxlength="255"
name="item[name]" size="255" type="text" /></div><br>
</div>
( I took out the html for the nested fields and some other fields for brevity)
<div class="form-actions">
<input name="commit" type="submit" value="Create Item" />
</div>
</form>
I've tested in both Chrome and Firefox. I've checked that the bootstrap-sass gem and simple_form gem are the same versions. I have no fancy customization css or javascript, just the #import 'bootstrap'; line in a bootstrap_custom.css.scss file in both apps. I don't know why the text input fields cover the whole width of the screen in the "Inventory" app, but the integer fields seem to be fine and rendering horizontally. What's wrong here?
I ran into a similar issue and found a pretty quick fix here http://www.iconoclastlabs.com/blog/using-twitter-bootstrap-3-with-simple_form
The simple fix is (after doing the normal simple form bootstrap init stuff -see below), you add the following code to an initializer (like config/initializers/simple_form_bootstrap.rb)
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
RangeInput
StringInput
TextInput
]
inputs.each do |input_type|
superclass = "SimpleForm::Inputs::#{input_type}".constantize
new_class = Class.new(superclass) do
def input_html_classes
super.push('form-control')
end
end
Object.const_set(input_type, new_class)
end
and you are off to the races.
The "normal simple form bootstrap init stuff" goes something like:
rails generate simple_form:install --bootstrap
If you want horizontal forms, add this to your simple_form config
config.form_class = "simple_form form-horizontal"
CAVEAT: Based on some recent comments, it appears this many not work for more recent versions of simple_form. I wrote the post some time ago and the project that was using this code (for me) is no longer using simple_form so it's hard to track down the exact version number. I believe this will work for verisions 2.x. Once you get to v3 you may have issues and have to find a different solution.
To override on per form basis, change:
<%= simple_form_for(#item, html: {class: 'form-horizontal' }) do |f| %>
to
<%= simple_form_for(#item, wrapper: :horizontal_form) do |f| %>
to change all forms to horizontal, change initializer:
config/initializers/simple_form_bootstrap.rb line:
config.default_wrapper = :vertical_form
to
config.default_wrapper = :horizontal_form
(remember to restart rails server after changing initializer)
to change just an individual input, change:
<%= f.input :on_order_qty %>
to
<%= f.input :on_order_qty, wrapper: :horizontal_form %>
Simple Form 3.1.0.rc1 has been released!! This supports bootstrap 3. Just update your gem to the latest version this will solve your problem. You can check the other enhancements through the change logs here https://github.com/plataformatec/simple_form/blob/v3.1.0.rc1/CHANGELOG.md
Just update your simple_form to
gem 'simple_form', '3.1.0.rc2'
And then re-run
$ rails generate simple_form:install --bootstrap
I tried quite many different solutions but, nothing helped until I've added wrapper: :horizontal_form line to each form inputs. And, I have the latest simple_form version: 3.2.1
For example:
= f.input :payment_term, wrapper: :horizontal_form
Hint: https://gist.github.com/chunlea/11125126/
Use simple form RC1. There is an entire example project: https://github.com/rafaelfranca/simple_form-bootstrap . I've just copied bootstrap initializer and followed horirozontal view example at https://github.com/rafaelfranca/simple_form-bootstrap/tree/master/app/views/examples.
If all the above doesn't work try gem
gem 'simple_form_bootstrap3'
Need to replace form_for with horizontal_form_for
Please check out the very helpful sample app here for usage of Simple Form and the Bootstrap toolkit on a Rails 4 application.:
http://simple-form-bootstrap.plataformatec.com.br/
Don't forget the docs page.
I had an issue with the full length of the input field spanning my entire page. Here is what I did and I hope it helps someone else.
Using simple_form 3.4.0
Open config/initializers/simple_form_bootstrap.rb
At the bottom of the page I changed the following:
From
config.default_wrapper = :vertical_form
config.wrapper_mappings = {
check_boxes: :vertical_radio_and_checkboxes,
radio_buttons: :vertical_radio_and_checkboxes,
file: :vertical_file_input,
boolean: :vertical_boolean,
datetime: :multi_select,
date: :multi_select,
time: :multi_select
}
end
To:
config.default_wrapper = :horizontal_form
config.wrapper_mappings = {
check_boxes: :horizontal_radio_and_checkboxes,
radio_buttons: :horizontal_radio_and_checkboxes,
file: :horizontal_file_input,
boolean: :horizontal_boolean,
datetime: :multi_select,
date: :multi_select,
time: :multi_select
}
end
Then restart your app to reinitialize.
When i use form-horizontal in my code, i also modify the different inputs with the bootstrap classes. For exemple with bootstrap 3:
<div class="form-group">
<%= f.label :name, class: "control-label col-sm-3" %>
<div class="col-sm-4"><%= f.text_field :name, placeholder: "Your placeholder", class: "form-control" %></div>
</div>
And now you can adjust the col-sm to col-sm-12 if you want the entire width of your app. I think it's easier to customize this way. ( col-sm are for bootstrap 3, if you need older version i think you have to use the old span- notation)
More info for bootsrap form here: doc
Here is an exemple of code with bootstrap 2 and simple form: doc
The output form with bootsrap 2 should look like this:
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputName">Name</label>
<div class="controls">
<input type="text" id="Name" placeholder="Name">
</div>
</div>
</form>
I think you need to set a control-group class div and a controls class div.
Here is the doc form the old syntax: doc
Hope it helps