SaveMe SaveMe - 5 months ago 16
jQuery Question

jQuery-Select2: Add ability to adding own entry on list

Quick desc:

I trying to add ability to adding own entry on list.
It's not even working when I left just

tags: true
nothing change.
Thanks in advance. Below is code and jsfiddle snipped.

HTML

<input id="placeSelect">


JavaScript/jQuery

var data = new Array();
data.push({
id: "search-0",
text: "Default"
});

$('#placeSelect').select2({
tags: "true",
width: '60%',
multiple: "true",
allowClear: "true",
placeholder: "Enter name of city",
data: data
});


Here is the jsfiddle link

EDIT:

Whole code on snippet here

Answer Source

It seems there's an issue with the input tag, change it to a select instead.

Select2 Documentation

Deprecated in Select2 4.0. It is now encouraged to use the select tag instead.

In past versions of Select2, a element could only be used with a limited subset of options. An was required instead, which did not allow for a graceful fallback for users who did not have JavaScript enabled. Select2 now supports the element for all options, so it is no longer required to use elements with Select2.