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

后端 未结 11 2115
没有蜡笔的小新
没有蜡笔的小新 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:24

    I had a similar problem. My data is provided by a remote server. I want some value to be entered in the selectize box, but it is not sure in advance whether this value is a valid one on the server.

    So I want the value to be entered in the box, and I want selectize to show the possible options just if like the user had entered the value.

    I ended up using this hack (which it is probably unsupported):

    var $selectize = $("#my_input").selectize(/* settings with load*/);
    var selectize = $select[0].selectize;
    // get the search from the remote server
    selectize.onSearchChange('my value');
    // enter the input in the input field
    $selectize.parent().find('input').val('my value');
    // focus on the input field, to make the options visible
    $selectize.parent().find('input').focus();
    

提交回复
热议问题