在 Rails 表单中,如何添加多选下拉列表?
In a Rails form, how to add a multiselect dropdown?
我有一个 Rails 表单,其中包含一个下拉列表,如下所示:
<%= f.select :facility_id, options_for_select(@entities.collect{ |e| [e.entity, e.entity] }, 1 ), {include_blank: '-Select-'}, { id: my_entity'} %>
我还有 2 个与上面类似的下拉菜单。
- 我想将上面的下拉菜单设为多选下拉菜单。我怎样才能做到这一点?
请帮忙!
谢谢
您可以通过在 select
中添加 multiple: true
来完成
示例:
<%= f.select :facility_id, options_for_select(@entities.collect{ |e| [e.entity, e.entity] }, 1 ), {include_blank: '-Select-'}, { id: my_entity'}, { :multiple => true, :size => 5 } %>
参考:[1][2]
您可能只需要将其添加到标签中
{ :multiple => true}
像这样
<%= f.select :facility_id, options_for_select(@entities.collect{ |e| [e.entity, e.entity] }, 1 ), {prompt: '-Select-', :multiple => true}, { id: my_entity'} %>
我有一个 Rails 表单,其中包含一个下拉列表,如下所示:
<%= f.select :facility_id, options_for_select(@entities.collect{ |e| [e.entity, e.entity] }, 1 ), {include_blank: '-Select-'}, { id: my_entity'} %>
我还有 2 个与上面类似的下拉菜单。
- 我想将上面的下拉菜单设为多选下拉菜单。我怎样才能做到这一点?
请帮忙!
谢谢
您可以通过在 select
multiple: true
来完成
示例:
<%= f.select :facility_id, options_for_select(@entities.collect{ |e| [e.entity, e.entity] }, 1 ), {include_blank: '-Select-'}, { id: my_entity'}, { :multiple => true, :size => 5 } %>
参考:[1][2]
您可能只需要将其添加到标签中
{ :multiple => true}
像这样
<%= f.select :facility_id, options_for_select(@entities.collect{ |e| [e.entity, e.entity] }, 1 ), {prompt: '-Select-', :multiple => true}, { id: my_entity'} %>