如果未满足某些条件,请防止下拉措施打开



我正在使用selectize.js在用户输入文本框中的查询时提供一些建议。但是,如果不满足某些条件,我想防止打开下拉菜单。我知道onDropdownOpen回调,但似乎该事件无法从那里停止。以下解决方法也不起作用。

onDropdownOpen: function($dropdown) {
    // [Test some variables here]
    $dropdown.collapse();
}

无论如何是否可以实现这一目标?

这是我尝试的似乎正在工作的https://plnkr.co/edit/difihiuxogkmxfdeht9l?p = preview

$(document).ready(function(){
  $('#input-tags').selectize({
    delimiter: ',',
    persist: false,
    create: function(input) {
        return {
            value: input,
            text: input
        }
    },
    onDropdownOpen: function(){
      // you can add your logic here to conditionally close the drop down
      this.close(); 
      // I had to set it to false because when it is true, this will run into infinite loop since while the input is in focus, it will trigger to open the drop down.
      this.settings.openOnFocus = false;
    }
});
});

最新更新