Skip to content

Instantly share code, notes, and snippets.

@mudassir0909
Created June 10, 2014 13:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mudassir0909/ed7eceb5d20e65721f63 to your computer and use it in GitHub Desktop.
Save mudassir0909/ed7eceb5d20e65721f63 to your computer and use it in GitHub Desktop.
Selectize plugin which gives an option to clear selection
Selectize.define( 'clear_selection', function ( options ) {
var self = this;
//Overriding because, ideally you wouldn't use header & clear_selection simultaneously
self.plugins.settings.dropdown_header = {
title: 'Clear Selection'
};
this.require( 'dropdown_header' );
self.setup = (function () {
var original = self.setup;
return function () {
original.apply( this, arguments );
this.$dropdown.on( 'mousedown', '.selectize-dropdown-header', function ( e ) {
self.setValue( '' );
self.close();
self.blur();
return false;
});
}
})();
});
@mudassir0909
Copy link
Author

@LeonB
Copy link

LeonB commented Aug 26, 2014

Is there an easy way to override the title?

@jumika
Copy link

jumika commented Jan 27, 2015

@LeonB Take a look at my fork!

@LouayH
Copy link

LouayH commented Mar 20, 2019

Isn't there any way to initialize the plugin after I update the selectize placeholder, so I can pass new placeholder as plugin title?

This is what I've tried, but it's not working

    selector.settings.placeholder = selected_category.adv_main_property_title;
    selector.updatePlaceholder();
    selector.initializePlugins({ 'clear_selection': { title: selector.settings.placeholder } });

P.S. when I console log selector.plugins.settings.clear_selection I can see my placeholder as a title there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment