简单表单输入为下拉列表而非选择框

时间:2015-06-27 09:23:27

标签: ruby-on-rails-3 simple-form

我有一个带有集合的输入,该集合应该显示为下拉列表,而是显示为选择框。我如何让它成为一个下拉?

<%= f.input :fund, collection: funds, prompt: 'Select Fund', label: false, input_html: { multiple: true } %>

2 个答案:

答案 0 :(得分:0)

as: :select添加到您的HTML并删除multiple: true属性。如果没有像Select2这样的JavaScript库,select标签作为下拉列表不支持多项选择。

<%= f.input :fund, as: :select, collection: funds, prompt: 'Select Fund', label: false %>

以下是每种类型的选择的示例:http://jsfiddle.net/scarver2/s1nckfq5/

CITE:https://github.com/plataformatec/simple_form#usage

答案 1 :(得分:0)

我回答了类似问题here,但您没有说明您正在使用的上下文(网络框架)。

您可以使用SimpleFormBootstrapBootstrap-Select。它有一个Rails Gem。有关详细信息,请参阅my other answer

相关问题