Bootstrap-select: Request: open and close methods

Created on 10 Jan 2018  路  4Comments  路  Source: snapappointments/bootstrap-select

Objective:
Similar to .selectpicker('toggle') , options like close and open are required

  1. .selectpicker('open') open all pickers
  2. .selectpicker('close') close all pickers

Purpose:
sometimes it is required to close down all bootstrap-select pickers while .selectpicker('toggle')only switched between open and closed states.
These options will help in achieve either opening or closing one or more selectpickers

Solution:

  1. add 2 functions after toggle function in source code
  2. Working fiddle after source change http://jsfiddle.net/bababalcksheep/RUAS4/563/

Tests:

  1. tested with container option as well and works
  2. tested and fires all respective events as well

Sample:
added open: function (e) { and close: function (e) { after toggle in source

    toggle: function (e) {
      e = e || window.event;

      if (e) e.stopPropagation();

      this.$button.trigger('click');
    },

    open: function (e) {
      e = e || window.event;

      if (e) e.stopPropagation();

      if  (!this.$newElement.hasClass('open'))  this.$button.trigger('click');      
    },

    close: function (e) {
      e = e || window.event;

      if (e) e.stopPropagation();

      if  (this.$newElement.hasClass('open'))  this.$button.trigger('click');      
    },
enhancement

Most helpful comment

+1

All 4 comments

+1

What is the status of this issue please?
Is there a way to close the select programmatically?
I only see method for toggle and that's not really what I need. Or is there a way to query whether select is opened so I could filter the opened ones and close them by toggle?

This change will be a part of the v1.14.0 release. This issue will be updated after it's made available.

Released in v1.14.0-beta!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndreasPresthammer picture AndreasPresthammer  路  3Comments

didip picture didip  路  4Comments

EmilMoe picture EmilMoe  路  4Comments

DjSunrise picture DjSunrise  路  3Comments

bhritch picture bhritch  路  3Comments