Skip to content

Instantly share code, notes, and snippets.

@bendytree
Created April 2, 2014 14:03
Show Gist options
  • Select an option

  • Save bendytree/9934794 to your computer and use it in GitHub Desktop.

Select an option

Save bendytree/9934794 to your computer and use it in GitHub Desktop.
A patch for bootstrap-select v1.5.4 to fix the setStyle function. Currently setStyle doesn't properly keep track of what style was set previously, so the old style is never removed.
(function(){
//create a select so we can access the selectpicker
var $div = $("<div><select></select></div>");
//get the prototype
var prototype = $div.find("select").selectpicker().data("selectpicker").constructor.prototype;
//keep track of the original setStyle
var setStyle = prototype.setStyle;
prototype.setStyle = function(style, status) {
//call original setStyle
setStyle.apply(this, arguments);
//THE ONLY CHANGE - SAVE STYLE SO IT CAN BE REMOVED NEXT TIME
if (style) {
this.options.style = style;
}
};
//get rid of our temporary div
$div.remove();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment