Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Deselect option when repressed #1863

Unanswered
authyrtyr asked this question in Q&A
Discussion options

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?

You must be logged in to vote

Replies: 2 comments

Comment options

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.

You must be logged in to vote
0 replies
Comment options

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');
}
});
}
});

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /