J'ai trouvé ce Bootstrap Select projet et son gem pour Rails . Je veux implémenter la recherche dans la balise select.
J'inspecte l'élément et voici la source HTML:
<select class="selectpicker" data-live-search="true">
<option>Hot Dog, Fries and a Soda</option>
<option>Burger, Shake and a Smile</option>
<option>Sugar, Spice and all things Nice</option>
</select>
Comment ajouter data-live-search="true"
dans mon tag de sélection de formulaire?
Mon formulaire sélectionner:
<%= f.select :food_id, options_for_select(Food.all.map{|c| [c.name, c.id]}, f.object.food_id), {}, {class: "form-control selectpicker"} %>
Ce que j'ai essayé
<%= f.select :food_id, options_for_select(Food.all.map{|c| [c.name, c.id]}, f.object.food_id), {}, {class: "form-control selectpicker", data: "live-search"} %>
Mais ça ne marche pas.
Essayer:
{class: "form-control selectpicker", "data-live-search" => "true" }
<%= f.select :food_id, options_for_select(Food.all.map{|c| [c.name, c.id]}, f.object.food_id), {}, {class: "form-control selectpicker", data: {"live-search": true}} %>
<%= f.select(:plan_id, {},{}, {'v-model'=>"plan_id",'@change'=>"onChange", class: "form-control"}) do %>
<% Plan.all.each do |plan| %>
<%= content_tag(:option,"#{plan.name.upcase} #{plan.max_items} #{number_to_currency(plan.price)}", value:plan.id, :data => {items: plan.max_items, price: plan.price}) %>
<% end%>
<% end%>