How to add data attribute in Rails form select tag?

前端 未结 4 1307
自闭症患者
自闭症患者 2021-02-18 14:33

I found this Bootstrap Select project and its gem for Rails. I want to implement search in the select tag.

I do inspect element and here is the HTML source:



        
相关标签:
4条回答
  • 2021-02-18 14:55

    Try:

    {class: "form-control selectpicker", "data-live-search" => "true" }
    
    0 讨论(0)
  • 2021-02-18 15:03
      <%= 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%>
    
    0 讨论(0)
  • 2021-02-18 15:05

    if you are passing a block to the select, you need to pass {} two times, e.g.

        => f.select :to_user_id, {}, {}, data: { placeholder: "Choisis des invités..." }, class: "chosen-image" do
          - User.find_each do |user|
            option(data-img-src="#{user_image_url_for(user)}" value="#{user.id}")
              = user.first_name
    
    0 讨论(0)
  • 2021-02-18 15:10
    <%= 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}} %>
    
    0 讨论(0)
提交回复
热议问题