ivaynberg/select2 — pull request #1365 by corinnaerin (2013-05-30 18:24:39+00:00)
Title: Ability to specify a placeholder nonempty option

We had a discussion in pull request https://github.com/ivaynberg/select2/pull/514 about the limitations of requiring that in order to use placeholders with a select, you must include an option with a blank value and blank text in order for it to work. In our application, at least, we commonly use the first option with either "0" or "-1" as it's value with a text of "-- Choose --" or something similar. Due to the size of our application and the sheer number of select boxes, it's necessary to have the select2 library use this option as its placeholder option and use its text as the placeholder itself.

The commits in the original pull request got messed up somehow (I think my eclipse replaced all tabs with spaces or something similar) so I just decided to create a new pull request for it.

As discussed, I added a new option ``placeholderOption``. This can either be a function which, given the select object, returns the option that should be used as a placeholder, or can be given the shortcut of ``'first'`` which indicates that the first option should be used regardless of its value and text. The text of placeholder will only be taken from the option if a placeholder is _not_ specified, either through the ``placeholder`` option or as a data attribute per usual. It is not required to use ``placeholderOption``... the original functionality of using the first blank option with a specified placeholder still works.

I tested all the scenarios I could think of. You can see them in action here: http://plnkr.co/edit/aabMRJqRSUCZKLJbKY3g?p=preview