当前位置: 动力学知识库 > 问答 > 编程问答 >

selectize.js : to clear selected value in onChange event

问题描述:

I am trying to clear out the value selected in the onChange event depending on a condition. Whether or not its already present in a selected list.

However i am not able to clear of the value using

$select[name][0].selectize.clear(); from inside the onChange object. I tried various versions of it , like using the elements id.

Please help me with this.

$select[name].selectize({

valueField: 'lot_name',

labelField: 'lot_name',

create: true,

options: res,

render: {

option: function (item, escape) {

return '<div>' +

'<span><strong>' + item.lot_name + '</strong></span>' +

'</div>';

},

option_create: function (data, escape) {

return '<div class="create">Map to <strong>' + escape(data.input) + '</strong>&hellip;</div>';

}

},

onChange: function (value) {

if($.inArray(value, selectedList) > -1){

alert("Lot " + value + " has already been selected. Please recheck your selection and try again");

$select[name][0].selectize.clear();

} else {

// else logic

}

}

});

网友答案:

This is the solution I found.

     /* Using the Below inside onChange event handler
      var obj = $(this);
      obj[0].setValue("");
     */


onChange: function (value) {
 var obj = $(this);
 if (($.inArray(value, selectedList) > -1)) {
   alert("Lot " + value + " has already been selected. Please recheck your selection and try again");
   obj[0].setValue("");
 } else {
}
},
分享给朋友:
您可能感兴趣的文章:
随机阅读: