How to add placeholder for select2 to search input
P粉5216974192023-10-22 22:01:07
0
2
743
How to make placeholders for select2 jQuery plug-in. There are a lot of answers on StackOverflow how to make placeholders there, but they are about placeholders for elements. I need to specify a placeholder for the search box, see image.
You can use this event:
It is enough to add the placeholder attribute to this event:
I had the same need and ended up writing a small extension for the
Select2
plugin.The plugin has a new option
searchInputPlaceholder
for setting a placeholder for the Search input field.Add the following code after the plugin’s js file:
usage:
Initialize the select2 plugin using the
searchInputPlaceholder
option:Demo:
Demo can be found at JsFiddle.
Updated May 9, 2020
Tested with the latest Select2 version (v4.0.13) - JsFiddle.
Github Repository:
https://github.com/andreivictor/select2-searchInputPlaceholder