2016-12-21 2 views
0

Ich benutze selectize.js, um einige Vorschläge zu machen, während der Benutzer eine Abfrage in eine Textbox eingibt. Ich möchte jedoch verhindern, dass das Dropdown geöffnet wird, wenn bestimmte Bedingungen nicht erfüllt werden. Mir ist der Rückruf onDropdownOpen bekannt, aber es scheint, dass das Ereignis von dort nicht gestoppt werden kann. Die folgende Problemumgehung funktioniert ebenfalls nicht.Verhindern, dass das Dropdown-Menü geöffnet wird, wenn bestimmte Bedingungen nicht erfüllt sind

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

Gibt es trotzdem, dies zu erreichen?

+0

Haben Sie versucht, 'if (Bedingung) return false;'? – connexo

+0

Eine gute Frage an die selectize.js Autoren. – Whothehellisthat

+0

@connexo Ja, nichts passiert. – cdonts

Antwort

1

Das ist, was ich versucht, das zu sein scheint zu funktionieren 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; 
    } 
}); 
}); 
+0

Funktioniert wie ein Zauber! – cdonts

Verwandte Themen