I'm currently trying to listen to click events on generated options inside the dropdown, but I'm currently unable to achieve this.
Since options aren't generated when the DOM loads, I'm delegating the event to the document listening for clicks on the dropdown's options. My code currently looks like this:
var $accountsSelectize = $('#accounts-input').selectize({
...
});
$(document).on('click', '.accounts-input-selectize .option', function(event) {
alert('An option was clicked!');
});
But this doesn't seem to be working. Any idea on why this is happening? Any clue regarding why this event isn't firing at all will be more than welcome.
Edit: Just an FYI, I'm adding a class to the HTML input element, that's why I'm listening for clicks on .accounts-input-selectize .option
:
<input type="text" id="accounts-input" class="accounts-input-selectize" placeholder="Search accounts">
My approach to an admitedly half-baked "solution" is to create a plugin that intercepts the default event listener for clicks on options:
The next step was to initialize Selectize using the previously created plugin, like this:
And that's it.