-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
-
I'd like to enhance my multiselects with selectize, but one functionality I haven't been able to get it to do is to deselect an option when the option is pressed again. Basically, I want a trigger that removes the selected option if they press the option again. I tried to bind it to .selectize-dropdown .option.selected but the event won't fire. I confirmed in dev tools that the event was attached to the element. I see a lot of stuff in the selectize.js file that stops propagation so I'm thinking that there's something there stopping this from working. I found a similar question asked in #1723 but there was no activity on it.
Does anyone know of a way to get this functionality? Either from a built-in function of the plugin that I missed or a way to get around the halting propagation?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments
-
Anyone who can suggest a possible way to get this functioning? I too am looking into how to get this kind of functionality added to my Selectize multiple dropdown.
Beta Was this translation helpful? Give feedback.
All reactions
-
This is a microplugin that I found that someone else had made and it seems work just fine. I modified it to work with what I was doing but it should be something easy to modify.
Selectize.define('click2deselect', function(options) {
var self = this;
var setup = self.setup;
this.setup = function() {
setup.apply(self, arguments);
// add additional handler
self.$dropdown.on('click', '[data-selectable]', function(e) {
let value = this.getAttribute('data-value');
if( this.classList.contains('selected') ) {
this.classList.remove('selected');
self.removeItem(value);
self.refreshItems();
self.refreshOptions();
}else{
this.classList.add('selected');
}
});
}
});
Beta Was this translation helpful? Give feedback.