Kumari Manisha Kumari Manisha - 2 years ago 144
Javascript Question

How to prevent select2 from taking user input as one of the tag suggestions

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:


<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">


tags: languagenames,

lanugagenames data:


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?

enter image description here

Answer Source

I didnt know this plugin before, but it looks great.

Try something like this:

     tags: languagenames,
     createSearchChoice : function(term){
        return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download