In the simple_form example repo on github, there is a block containing the wrapper information. https://github.com/rafaelfranca/simple_form-bootstrap/blob/master/app/views/examples/_horizontal_form_sf.html.erb
It works fine, but seems to be a lot of extra setup to add for every form. Is there some way to add name this information and add it as a parameter?
<%= simple_form_for @user_horizontal, url: create_horizontal_examples_url, as: 'user_horizontal', html: { class: 'form-horizontal' },
wrapper: :horizontal_form,
wrapper_mappings: {
check_boxes: :horizontal_radio_and_checkboxes,
radio_buttons: :horizontal_radio_and_checkboxes,
file: :horizontal_file_input,
boolean: :horizontal_boolean
} do |f| %>
<%= f.error_notification %>
<%= f.input :email, placeholder: 'Email' %>
At a view helper, add:
def wrapped_form(resource, options = {}, &block)
options[:html] = { class: 'form-horizontal'}
options[:wrapper] = :horizontal_form
options[:wrapper_mappings] = {
check_boxes: :horizontal_radio_and_checkboxes,
radio_buttons: :horizontal_radio_and_checkboxes,
file: :horizontal_file_input,
boolean: :horizontal_boolean
}
simple_form_for(resource, options, &block)
end
And then you can just use like this:
<%= wrapped_form @user_horizontal, url: create_horizontal_examples_url, as: 'user_horizontal' do |f| %>
<%= f.error_notification %>
<%= f.input :email, placeholder: 'Email' %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With