Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selectize.js: onChange event triggered on load Page


In selectize, I wont call event, but is it don't working
jquery event Working,
Selectize event don't working
Help please.

<div><select id='select'>
<option value="0">Item 0</option>
<option value="1">Item 1</option>
<option value="2">Item 2</option>

$(function () {
$('select').on('change', function () {
    alert("Original input event: Change");
});
$('select').selectize({
    onChange: function () {
        alert("Selectize event: Change");
    }
});
// this triggers an the event
$('#select').trigger( "change" );

});

http://jsfiddle.net/6zyums3d/9/

like image 228
Max SMI Avatar asked Nov 02 '25 13:11

Max SMI


2 Answers

$('select').selectize({
    onInitialize: function() {
        this.trigger('change', this.getValue(), true);
    },
    onChange: function(value, isOnInitialize) {
        alert('Selectize changed: ' + value);
    }
});

Make sure that you passed value parameter to the change callback. Otehrwise it would be undefined

like image 89
Oleg Avatar answered Nov 04 '25 11:11

Oleg


This is what worked for me with respect to triggering a change event on the select element itself.

$('select').selectize({
   onChange: function() {
     this.$input[0].dispatchEvent(new Event("change"))
   }
})
like image 33
Minimul Avatar answered Nov 04 '25 12:11

Minimul