如何在 Rails 表单选择标签中添加数据属性? [英] How to add data attribute in Rails form select tag?

查看:37
本文介绍了如何在 Rails 表单选择标签中添加数据属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了这个 Bootstrap Select 项目及其 Gem for Rails.我想在select标签中实现搜索.

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

我确实检查了元素,这里是 HTML 源代码:

I do inspect element and here is the HTML source:

<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>

如何在表单选择标记中添加 data-live-search="true"?

How do I add data-live-search="true" inside my form select tag?

我的表单选择:

<%= f.select :food_id, options_for_select(Food.all.map{|c| [c.name, c.id]}, f.object.food_id), {}, {class: "form-control selectpicker"} %>

我尝试过的:

<%= 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"} %>

但它不起作用.

推荐答案

尝试:

{class: "form-control selectpicker", "data-live-search" => "true" }

这篇关于如何在 Rails 表单选择标签中添加数据属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆