Implement bootstrap-select

Hello everyone,

I am trying to implement bootstrap-select, but could not find a way to add attributes to options tag.

The HTML should look like this.

<select class="selectpicker" multiple data-live-search="true">
  <option data-tokens="ketchup mustard">Hot Dog, Fries and a Soda</option>
  <option data-tokens="mustard">Burger, Shake and a Smile</option>
  <option data-tokens="frosting">Sugar, Spice and all things nice</option>
</select>

My code looks like this…

    <%=
      multiple_select(f, :readers,
        select_readers(),
        selected: event_selected_readers(@changeset.data),
        class: "selectpicker",
        data_style: "btn-info",
        data_mobile: true,
        data_width: "fit"
      )
    %>

I can add data_live_search: true, but I cannot find a way to add data-tokens attribute to options.

Before I do this with Javascript, I wanted to know if there is a cleaner solution :slight_smile:

Thanks for taking time.

1 Like

Sorry for the question,

I made it working by using the string “true” instead of true…

    <%=
      multiple_select(f, :readers,
        select_readers(),
        selected: event_selected_readers(@changeset.data),
        class: "selectpicker",
        data_style: "btn-info",
        data_mobile: true,
        # IMPORTANT! data_live_search should be the string "true", and not true
        data_live_search: "true"
      )
    %>
2 Likes