Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define placeholder text in Select2 JQuery Plugin

I can never define placeholder text in Select2 JQuery Plugin. I tried the code

$("#first").select2({
    placeholder: {id: "", text: "Choose an option…"}
});

but it doesn't work for me. My code is here

And, how to rectangle for search be rounded, what is the version of Select2?

like image 919
Godfather Avatar asked Jan 14 '23 05:01

Godfather


1 Answers

You have to add an empty option to the beginning of your select element:

<select name="first" id="first"> 
    <option></option>
    ...
</select>

Then simply add a placeholder like this:

$(document).ready(function(){
    $("#first").select2({
        placeholder: "Your placeholder",
        allowClear: false
    });
});
like image 65
Amin Avatar answered Jan 17 '23 14:01

Amin