how to implement select2 with lock selection

穿精又带淫゛_ 提交于 2020-04-11 03:13:39

问题


Hi guys I am trying to use select2 with one disabled value.

I am trying to implement it like

$('#select_currency').select2('data', preloaded_data);

I have been reading about Lock selections but I am not able to implement it, could you please someone let me know how to implement it or is there any tutorial about it. Thank you.


回答1:


You can easely add locked="locked" if you use v3.5 http://select2.github.io/select2/#locked-selections.

But in v.4.x this functionality is removed.

I've found solution (or hack:) ) for v.4.x, a little bit dirty with error in console, but it works. Anyway it is best solution what I've found. Check my jsfiddle:

https://jsfiddle.net/o3s3y42e/4/




回答2:


And in a select dropdown you can just add the locked="locked" attribute.

<select id="sharewith" multiple="true">
  <option value="self" selected="selected" locked="locked">myself</option>
</select>   



回答3:


It's simple, just pass all items you want to lock, e.g

$('#select_currency').select2('data', [{id:'myr', text:'Malaysia Ringgit', locked:true}]);


来源:https://stackoverflow.com/questions/16564425/how-to-implement-select2-with-lock-selection

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