I have tried to integrate tag/autocomplete for my site. Its working through option text. I am almost close to result but still hanging.
Now when you try to select option text there will appear related text. But now i want to appear kathmandu or related option text searching via option value also.
Ex: when we will search value a001 kathmandu will appear and select same as a002 it will appear pokhara
$("select").select2({
tags: "true",
placeholder: "Select an option",
allowClear: true,
width: '100%',
createTag: function (params) {
var term = $.trim(params.term);
if (term === '') {
return null;
}
return {
id: term,
text: term,
value: true // add additional parameters
}
}
});
.select2-container {
max-width: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet"/>
<select class="custom-select" multiple="multiple">
<option value="a001">Kathmandu</option>
<option value="a002">Pokhara</option>
<option value="a003">Lalitpur</option>
</select>
I think i am close after searching via value and click on it it will show relevant option with id. But i want only option text like pokhara kathmandu not an ID on select area.