Select2 supports displaying a placeholder by default using the placeholder
option. This can be either a data object matching the placeholder option, or a string to display as the placeholder if you are using a blank placeholder option.
This usually means that you do not have a blank <option></option>
as the first option in your <select>
.
Note that this does not apply to multiple selects, as the browser does not select the first option by default when multiple selections can be made.
Yes, Select2 supports placeholders for all configurations. You will still need to add in the placeholder option if you are using a single select.
The placeholder
option allows you to pass in a data object instead of just a string if you need more flexibility. The id
of the data object should match the value
of the placeholder option.
The placeholder option should go through the standard templating methods, including templateSelection
, so you can change how it is displayed.
Select2 uses the native placeholder
attribute on input boxes for the multiple select, and that attribute is not supported in older versions of Internet Explorer. You need to include Placeholders.js on your page, or use the full build, in order to add placeholder
attribute support to input boxes.