user1740381
user1740381

Reputation: 2199

Select2 example is not working

I am trying to use Select2.js plugin. I have created a fiddle of the simplest example of select2 but i can't figure out why this is not working ?

http://jsbin.com/edeseh/2/edit

you can see in the fiddle that selection of items in selectlist and allow clear is not working.

Can anybody please help me, what i am doing wrong here ?

Upvotes: 8

Views: 27367

Answers (2)

Kelvin Barsana
Kelvin Barsana

Reputation: 864

Older versions require you to add 'select2' class in the dropdown.

Upvotes: 0

Gaurav
Gaurav

Reputation: 8487

You should use options value to enable selection

and

you should use an empty option for showing placeholder and allowClear option.

Here is the working fiddle :

http://jsbin.com/edeseh/8/edit

Main code copied from the link:

HTML:

<select id="e2" style="width:200px;">
  <option value=""><option>
  <option value="1">Mustard</option>
  <option value="2">Ketchup</option>
  <option value="3">Relish</option>
</select>

JavaScript:

$("#e2").select2({
  placeholder: "Select a State",
  allowClear: true
});

Upvotes: 11

Related Questions