Implemented Select2 in my project. Using the tag feature provided in the plugin. The feature works as suggested in the documentation, however I am stuck at one point.
I have initialized the tag as follows:
HTML
<div class="form-group">
<label for="languages">Languages <span class="mandatory">*</span> :</label>
<input type="text" required="" placeholder="Languages" name="languages" id="languages" class="form-control">
</div>
JS:
$('#languages').select2({
tags: languagenames,
});
lanugagenames data:
[{"id":"1","text":"Afrikaans"},{"id":"2","text":"Albanian"},{"id":"3","text":"Arabic",....}]
On entering characters in the input box, I get suggestions in the drop-down, however I am also getting the entered characters as one of the suggestions (screen attached). For example, while trying to enter english, I enter "En" and it is present as one of the suggestions. I checked the data set and there is not entry for "En". I cannot find any particular configuration to stop this extra entry. Any suggestion on how I can prevent this extra entry from appearing?
I didnt know this plugin before, but it looks great.
Try something like this:
$('#languages').select2({
tags: languagenames,
createSearchChoice : function(term){
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With