0

I currently have a Multi Select Box that groups Rooms with their respective Building.

Everything works great, except, I would like to add an ID to each option.

How can I do this?

FORM

<div class="form-group">
    <%= f.grouped_collection_select(:room_ids, Building.order('name ASC'), :rooms, :name, :id, :name, {include_blank: false}, {multiple: true, size: 10, :class => "form-control"}) %>
</div>

HTML

<select multiple="multiple" size="10" class="form-control" name="key[room_ids][]" id="key_room_ids" data-parsley-multiple="key[room_ids][]" data-parsley-id="5221">
  <optgroup label="Accounting Library">

    ###Is their a way to add an ID to this so I can manipulate it with javascript?
    <option value="142">105</option>
    <option value="143">105A</option>

  </optgroup>
  <optgroup label="Ahmanson Center">
    <option value="721">fad</option>
    <option selected="selected" value="144">105B</option>
  </optgroup>
</select>
Serge Pedroza
  • 2,160
  • 3
  • 28
  • 41

1 Answers1

1

I don't believe there is any way to add an id to each option using grouped_collection_select, but you can easy select an option using jQuery. For example to select the option with value = '721' use the following selector:

$('#key_room_ids option[value="721"]')
infused
  • 24,000
  • 13
  • 68
  • 78