todc / todc-select2

Google-themed fork of Select2. Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.
http://todc.github.com/todc-select2/
Other
112 stars 17 forks source link

Why the placeholder doesn't work? #5

Closed larryzhao closed 11 years ago

larryzhao commented 11 years ago

Hi, Tim,

Sometime the placeholder confuses me, why it doesn't work like in here: http://jsfiddle.net/9Mtr3/

Best Regards. Larry

todc commented 11 years ago

Hi Larry,

Two reasons:

1) You already have an option selected in your example, "California". The placeholder won't show when an option is selected.

2) Per the docs:

Note that because browsers assume the first option element is selected in non-multi-value select boxes an empty first option element must be provided (<option></option>) for the placeholder to work.

So you need an empty option element as the first item in the list.

Here's an updated jsfiddle that works with placeholders: http://jsfiddle.net/9Mtr3/1/

larryzhao commented 11 years ago

Thanks a lot, Tim!