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" ); 

});

5

4 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

Try to trigger the event like this:

$('#select')[0].selectize.trigger( "change" ); 
1

Trigger like this,

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

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")) } }) 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like