Skip to content

Loading…

Default option as prompt with value="" does not work #424

Closed
johnavance opened this Issue · 2 comments

2 participants

@johnavance

NOTE: This has NOTHING to do with placeholder. Please look at the jsfiddle below.

Setting a null value for the first option in the select will result in a blank Select2 box - that is, no prompt.

<option value="">Pick one</option> 

does not show "Pick one" as the prompt text in the select2 box.

<option>Pick one</option>

does work. This is an issue when using select and select_tag form helpers in rails, since the :prompt option will generate a first option with a null value.

See this jsfiddle: http://jsfiddle.net/cjmCE/3/

@johnavance

In initSelection, this line:

if (this.opts.element.val() === "" ) {

should be changed to this:

if (this.opts.element.val() === "" && this.opts.element.text() === "") {
@johnavance

I did not submit a pull request because I don't know Select2 well enough to determine what side effects this would have, or whether I've missed another location where a similar change needs to be made.

@ivaynberg ivaynberg pushed a commit that closed this issue
Kevin Brown Fixed placeholder detection. Fixes #424. c4c1cba
@ivaynberg ivaynberg closed this in c4c1cba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.