Reputation: 459
I have this line of code:
= f.input :goal, as: :select, input_html: {class: "select2"}, wrapper_html: {class: "form-fields"}
which I would like to turn to
= f.input :goal, as: :select2
using a custom input in simple_form. How do I achieve this? So far, I have:
class Select2Input < SimpleForm::Inputs::StringInput
def input
input_html_options[:class]<< 'select2'
end
end
Upvotes: 2
Views: 5896
Reputation: 872
This should get you half-way there:
class Select2Input < SimpleForm::Inputs::CollectionSelectInput
end
and
<%= f.input :email, as: :select2, wrapper_html:{class: "form-fields"} %>
You may have to create a custom wrapper for the select2 input in config/initializers/simple_form.rb
to be able to use it in the way you really want.
Upvotes: 0
Reputation: 6486
These may be of some help, though I am not very familiar with simple form.
https://github.com/plataformatec/simple_form
https://github.com/plataformatec/simple_form/wiki/Custom-inputs-examples
simple_form custom input with custom wrapper
Upvotes: 2