Wrapper mappings in simple_form

In the simple_form repo example on github, there is a block containing information about the wrapper. https://github.com/rafaelfranca/simple_form-bootstrap/blob/master/app/views/examples/_horizontal_form_sf.html.erb

It works great, but there seems to be a lot of extra tweak for each form. Is there any way to add 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' %> 
+6
source share
1 answer

In the 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 it 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 %> 
+15
source

Source: https://habr.com/ru/post/972491/


All Articles