Reputation: 1793
I need to allow users select ONLY allowed tags in select.
Currently I have that:
$("input#id_txtcolor").select2({tags:["red", "green", "blue"]});
Can you help me please with that?
Upvotes: 16
Views: 6033
Reputation: 1799
Sometimes we developer don't use our 7th sense that is common sense also happened with me struggled for 2 hours then it clicked my sense..
if you want user to select only allowed values then its no more tagging its selecting So just remove tags:true
option and keep mulitple
attribute in select, provide options directly in select element or load remote data.
Upvotes: 16
Reputation: 1453
as of 3.3 you can specify your own createSearchChoice when using tags that will always return null, thus preventing the default choice from being created.
$().select2({
createSearchChoice: function() { return null; },
tags:...
});
Upvotes: 31