Using Selectize.js, I'm trying to initialize the dynamically pre-select one of the item of the list without triggering the onItemAdd
event. In the following code, the event is triggered even if the silent
parameter is truthy:
$(function () {
$('select').selectize({
onItemAdd: function () {
alert("Add item");
}
});
// this triggers an the event
$('select')[0].selectize.addItem('2', true);
});
JSFiddle: http://jsfiddle.net/zuzat0dc/1/
According to the documentation:
addItem(value, silent)
: "Selects" an item. Adds it to the list at the current caret position. If "silent" is truthy, no change event will be fired on the original input.
Any idea how to avoid triggering the onItemAdd
event? Is the silent
parameter b0rked or should I use the change
event instead?
off(...)
andon(...)
functions to disable the handler, add the item then re-enable to handler, but that doesn't look like the way it should be done =/ – Froe.on()
and.off()
event methods of the selectize instance – Froe