简体   繁体   中英

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 .

<%= 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. 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}  %> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM