简体   繁体   中英

:prompt for select_tag does not appear in the box

Using this code :

= f.select :how_did_you_hear, HOWD_YOU_HEAR, {:prompt => "HQCard found by"}, :style => "width: 142px;"

The prompt is seen as blank, and the first selection is "HQCard found by". Then followed by a blank space, and the collection of items.

How can I make it appear as a default within the selection box as default?

Easy to use the :include_blank :

f.select :how_did_you_hear, HOWD_YOU_HEAR, :style => "width: 142px;", {:include_blank => '- Select HowD U Hear -' }

Documentation

Wow Rails.. what a hack.

So if you use unconventionally allow_blank and selected it works :

= f.select :how_did_you_hear, HOWD_YOU_HEAR, { :include_blank => "HQCard found by", :selected => "HQCard found by"}, :style => "width: 142px;"

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