-1

I have a Rails form which includes a dropdown as shown below:

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

I also have 2 more dropdowns similar to the one above.

  1. I would like to make the above dropdown as a multiselect dropdown. How can I achieve that?

Please help!

Thanks

Biju
  • 638
  • 6
  • 23

2 Answers2

1

You may just need to add this to the tag { :multiple => true} like this

<%= f.select :facility_id, options_for_select(@entities.collect{ |e| [e.entity, e.entity] }, 1 ), {prompt: '-Select-', :multiple => true}, { id: my_entity'} %>
Linh Nguyen
  • 905
  • 9
  • 23
  • That seems to work. Quick question though pls? How can I select multiple entries in this dropdown from the UI? – Biju Nov 07 '19 at 09:30
  • Using shift key or control key while select – Linh Nguyen Nov 07 '19 at 09:43
  • Thanks much. I made a syntax mistake and hence the I was not able to select multiple items. It's fixed now. Sorry about the dumb question. I have raised another related question here - https://stackoverflow.com/questions/58746270/in-rails-dropdown-how-to-display-all-column-names-from-a-model Would you mind taking a look please? Thanks much in advance! – Biju Nov 07 '19 at 10:04
0

You can do it by adding multiple: true in select

Example:

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

Reference: [1][2]

Vishal
  • 791
  • 7
  • 20