0

I am using Bootstrap-select in my project. Is it possible to add a callback when Select has been opened? Code below does not work.

var sp = $.fn.selectpicker.constructor.prototype.show;
$.fn.selectpicker.constructor.prototype.show = function () {
  sp.call(this);
  if (this.options.callback) {
    //console.log('is callback!');
    this.options.callback();
  }
};
$('.selectpicker-state').selectpicker({
  title: null,
  callback: function() {
    alert('show!');
  }
});
ArtA
  • 3
  • 1
  • 2

1 Answers1

1

You can use the bootstrap dropdown event shown http://getbootstrap.com/javascript/#dropdowns and see the Events section

$('#myDropdown').on('show.bs.dropdown', function () {
    // do something…
})
silviomoreto
  • 5,629
  • 3
  • 30
  • 41
  • Yes. I tried it. but it looks that the event does not fire. I tried to bind a handler with a delay, but it did not help. I still look for the reason. Thank you! – ArtA Jul 10 '14 at 08:13
  • Try the other events. I think that some of them should work, because bootstrap-select keep all of the bootstrap dropdown behavior – silviomoreto Jul 10 '14 at 13:50
  • 1
    Yes. According to the documentation the event fires on the "parent" not the toggle. Thank you for your time! Help here: [http://stackoverflow.com/questions/19936181/bootstrap-3-dropdown-events-not-firing](http://stackoverflow.com/questions/19936181/bootstrap-3-dropdown-events-not-firing) and/or here [http://stackoverflow.com/questions/21857779/process-for-using-show-bs-dropdown-in-bootstrap](http://stackoverflow.com/questions/21857779/process-for-using-show-bs-dropdown-in-bootstrap) – ArtA Jul 14 '14 at 14:03