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
if you search a001
then output is display id and text both in output. Learn placeholder.
If the value is an object, the object should be compatible with Select2's internal objects. The id should be the id to look for when determining if the placeholder should be displayed. The text should be the placeholder to display when that option is selected.
Example : search a001
after enter display kathmandu and a001 in textbox
using placeholder
in select2
placeholder: {
id: "-1",
text: "Select an option",
}
$("select").select2({
tags: "true",
placeholder: {
id: "-1",
text: "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;
}