javascript select2 allowed tags

百般思念 提交于 2019-12-03 15:35:40

问题


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?


回答1:


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:...
});



回答2:


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.



来源:https://stackoverflow.com/questions/14756309/javascript-select2-allowed-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!