How to set a value for a selectize.js input?

后端 未结 11 2100
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 23:51

I have a form from which I would like to copy some default values into the inputs. The form inputs are using the selectize.js plugin. I would like to set some of the form

11条回答
  •  执笔经年
    2020-12-14 00:29

    Answer by the user 'onlyblank' is correct. A small addition to that- You can set more than 1 default values if you want.

    Instead of passing on id to the setValue(), pass an array. Example:

    var $select = $("#my_input").selectize();
    var selectize = $select[0].selectize;
    var yourDefaultIds = [1,2]; # find the ids using search as shown by the user onlyblank
    selectize.setValue(defaultValueIds);
    

提交回复
热议问题