Marking text in jquery select2
<select multiple id="e1" style="width:300px">
<option value="AL">Alabama</option>
<option value="Am">Amalapuram</option>
<option value="An">Anakapalli</option>
<option value="Ak">Akkayapalem</option>
<option value="WY">Wyoming</option>
</select>
$("#e1").select2({'placeholder': ' ','allowClear': true});
it works great for consistent text. But I want to mark the text (which doesn't match any of the options). Please help.
find demo code in the following link. http://jsfiddle.net/marcusasplund/jEADR/2/
source to share
You have a tags option, but it cannot be used with an element select
$("#e1").select2({
tags: [{
"id": "AL",
"text": "Alabama"
}, {
"id": "Am",
"text": "Amalapuram"
}, {
"id": "An",
"text": "Anakapalli"
}, {
"id": "Ak",
"text": "Akkayapalem"
}, {
"id": "WY",
"text": "Wyoming"
}]
});
<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.css"/>
<input id="e1" style="width:300px" />
source to share
There select2
is an option tags
that allows you to have unrivaled text tags
, but there are some problems here.
- This will prevent you from setting a parameter
tags
if you bind the pluginselect2
toselect
. To do this, you need to bindselect2
toinput
.
-
select2
The version4.0
allows you to add a parametertags
to the controlselect
.
So the solution is either you need to update to the latest plugin or you need to bind
select2
to an elementinput
.
source to share