Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend bootstrap select plugin

In my previous question I was talking about the bootstrap select plugin where the destroy method is doing something that I don't want. I edit manually the plugin but this is not a good practice.

Bootstrap select destroy removes the original select from DOM

I would like to extend the plugin with a custom method so that it can do exactly wat I want.

I extend the plugin with folloing method:

$.extend(true, $.fn.selectpicker.prototype, {
    customRemove: function () {
        this.$newElement.remove();
        this.$element.show();
    }
});

This is located in another js file under the bootstrap select script file.

How do I call this new method? I tried the following without success:

$('select#begin' + _week + _day).selectpicker("customRemove");

or

$('select#begin' + _week + _day).selectpicker().customRemove();

Am I missing something?

The original method of the destroy function in the bootstrap select plugin:

remove: function () {
  this.$newElement.remove();
  this.$element.show();
}
like image 585
Mivaweb Avatar asked Dec 06 '14 17:12

Mivaweb


1 Answers

I think, you have the correct answer in other your question:
https://stackoverflow.com/a/31852632/4928642

jQuery.fn.selectpicker.Constructor.prototype.customRemove = function () {
  this.$newElement.remove();
  this.$element.show();
};

then

$smth.selectpicker("customRemove");
like image 175
2 revs Avatar answered Sep 18 '22 03:09

2 revs