user3477051
user3477051

Reputation: 459

Simple_form custom input

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

Answers (2)

RajeshM
RajeshM

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

Related Questions