【问题标题】:In a Rails form, how to add a multiselect dropdown?在 Rails 表单中,如何添加多选下拉菜单?
【发布时间】:2019-11-07 08:06:14
【问题描述】:

我有一个 Rails 表单,其中包含如下所示的下拉列表:

    <%= f.select :facility_id, options_for_select(@entities.collect{ |e| [e.entity, e.entity] }, 1 ), {include_blank: '-Select-'}, { id: my_entity'} %>

我还有 2 个类似于上面的下拉菜单。

  1. 我想将上述下拉菜单设为多选下拉菜单。我怎样才能做到这一点?

请帮忙!

谢谢

【问题讨论】:

    标签: ruby-on-rails drop-down-menu multi-select


    【解决方案1】:

    您可能只需将其添加到标签中 { :multiple =&gt; true} 像这样

    <%= f.select :facility_id, options_for_select(@entities.collect{ |e| [e.entity, e.entity] }, 1 ), {prompt: '-Select-', :multiple => true}, { id: my_entity'} %>
    

    【讨论】:

    • 这似乎行得通。请快速提问?如何从 UI 中选择此下拉列表中的多个条目?
    • 在选择时使用 shift 键或 control 键
    • 非常感谢。我犯了一个语法错误,因此我无法选择多个项目。现在已经修好了。抱歉这个愚蠢的问题。我在这里提出了另一个相关问题 - stackoverflow.com/questions/58746270/… 你介意看看吗?非常感谢!
    【解决方案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]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-14
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      相关资源
      最近更新 更多