在Rails中选择下拉列表的占位符文本

时间:2014-03-04 20:09:15

标签: ruby-on-rails jquery-chosen

我正在chosen使用rails,但无法为我的下拉菜单设置占位符文字。

我尝试了:allow_blank => "Please pick one"prompt: "take a card",但他们都在下拉列表中添加了占位符文本作为可选项。文档有点简单,似乎无法找到有关rails采用的好文档。

宝石:

gem 'chosen-rails'
gem 'chosen-sass-bootstrap-rails', github: 'duncanparkinson/chosen-sass-bootstrap-rails' # dependency versions less stringent

目前有:

= f.input :applying_as, collection: @my_collection, prompt: "test"

2 个答案:

答案 0 :(得分:1)

你在占位符的正确轨道上:

f.input :applying_as, input_html: { "data-placeholder" => "..." }

f.input :applying_as, input_html: {data: { placeholder: "..." }}

取决于您的偏好以及是否还要添加其他数据属性。

答案 1 :(得分:0)

试试这个:

jQuery(document).ready(function(){
    jQuery(".chosen").data("placeholder","Select Frameworks...").chosen();
});

reference