简体   繁体   English

如何为option_form_collection启用多项选择?

[英]How do I enable multiple selection for option_form_collection?

I can't figure out how to enable multiple selection for a input in Ransack . 我不知道如何在Ransack中为输入启用多重选择。

<%= search_form_for @q,url: search_table_path do |f| %> 
   <%= f.label :country_code_eq %>

   <%= f.select :country_code_eq, 
    options_from_collection_for_select(Country.all, :code, :name),
    {prompt: 'Select a Country',multiple: true,include_blank: false}%> 

   <%= f.label :date_start %>
   <%= f.text_field :date_start %>
   <%= f.submit %> 
<% end %>

The multiple: true does not work as I expected. 倍数:true不符合我的预期。 It only show a normal dropdown box not a multiple selection box. 它仅显示一个普通的下拉框,而不显示多个选择框。

My first question is how to enable multiple selection ? 我的第一个问题是如何启用多重选择?

And my Second question is how do I keep the selected value and show it after the page loaded in selection box ? 我的第二个问题是如何保留所选值并在选择框中加载页面后显示它?

我找到了答案

<%= f.select :country_code_in, Country.all.map {|country| [country.name,country.code] }, {include_blank: 'All'}, {multiple: true}  %> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在此Rails 2选择表单中设置所选选项? - How do I set a selected option in this Rails 2 selection form? 具有collection_select和多项选择的嵌套表单 - Nested form with collection_select and multiple selection 如何在单击按钮时使表单中的多个输入显示为其他表单上的选择选项值? - How do I make multiple inputs in a form appear as a select option value on different form on button click? 如何在Ruby on Rails上创建选择表单? - How do I create a selection form on Ruby on Rails? 如何使用 capybara 以简单的形式测试集合输入 - How do I test collection input in simple form using capybara 如何在 rails 表单中启用 mutliselect 下拉选择中的某些字段 - How to enable certain fields on mutliselect drop down selection in rails form 如何使用simple_form从集合中返回对象? - How do I return the object from a collection with simple_form? 如何从collection_select表单中获取ID? - How do i grab an id from a collection_select form? 如何在Simple Form gem中为集合的“ priority:”选项实现i18n - How to implement i18n in the Simple Form gem for a collection's “priority:” option 如果一个集合智能地具有多个产品,如何在集合项的显示中添加逗号? - How do I add commas to the display of collection items if a collection has multiple products intelligently?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM