1

我有这行代码:

= f.input :goal, as: :select, input_html: {class: "select2"}, wrapper_html: {class: "form-fields"}

我想求助

= f.input :goal, as: :select2

在 simple_form 中使用自定义输入。我如何实现这一目标?到目前为止,我有:

class Select2Input < SimpleForm::Inputs::StringInput
  def input
    input_html_options[:class]<< 'select2'
  end
end
4

2 回答 2

0

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.

于 2014-08-21T04:53:39.347 回答
0

这些可能会有所帮助,尽管我对简单的形式不是很熟悉。

https://github.com/plataformatec/simple_form

https://github.com/plataformatec/simple_form/wiki/Custom-inputs-examples

带有自定义包装器的 simple_form 自定义输入

于 2014-08-20T19:20:41.180 回答