fenec
fenec

Reputation: 5806

how can i add raw html in simple_form?

i am trying to add the attribute "multiple" to my select tag like this :

  <select class="chosen-select" id="segment_people" name="segment[people]" **multiple**>
    <option value="2">john</option>
    <option value="3">chico</option>
    <option value="4">glenn</option>
    <option value="5">chico</option>
    <option value="21">glenn</option>
  </select> 

i am using simple_form in my project but i can't find a way to do it, can i inject raw html in my tags?

here is my form code:

<%= simple_form_for @segment do |f| %>

  <%= f.input :name %>
  <%= f.input :segment %>
  <%= f.input :broadcast_date %>
  <%= f.input :comment %>
  <%= f.select :people,  Person.all.map { |u| [u.first_name, u.id] },
                                      { include_blank: true },
                                      { class: 'chosen-select' } %>  
  <%= f.button :submit %>
<% end %>

Upvotes: 1

Views: 1273

Answers (1)

vee
vee

Reputation: 38645

I don't think you can add an attribute without a value. You can add multiple: true to the html_options as follows:

<%= f.select :people,  Person.all.map { |u| [u.first_name, u.id] },
                                  { include_blank: true },
                                  { class: 'chosen-select', multiple: true } %>

This will add multiple="multiple" to your select field.

Upvotes: 3

Related Questions