简体   繁体   中英

Placeholder text for Dropdown with Chosen in Rails

I'm using chosen for rails , but can't set the placeholder text for my dropdown menus.

I've tried :allow_blank => "Please pick one" and prompt: "take a card" , but both of them add the placeholder text as a selectable option in the dropdown. Documentation is a bit squirrely and can't seem to find good documentation for the rails adoption.

gems:

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

Currently have:

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

You were on the right track with placeholder:

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

or

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

depending on your preferences and whether you have other data attributes to add.

try this:

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

reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM