Select2 - make it readonly (not disabled!) from js

前端 未结 5 1309
自闭症患者
自闭症患者 2021-02-12 12:05

How can I dynamically make a select2 combobox read-only?

Here\'s what I\'ve tried so far:

$(\'...\').attr({\'reado         


        
5条回答
  •  说谎
    说谎 (楼主)
    2021-02-12 12:53

    See: http://select2.github.io/select2/

    I did it with:

    $("#modelname-fieldname").select2({disabled:readonly});
    

    Where:

    • modelname-fieldname is as in: $form -> field($modelname, "fieldname") -> widget(Select2::classname(), [ ... ]);
    • readonly is true, false or a string readonly

    Optionally you can change the cursor when hovering over the select2 field.

提交回复
热议问题