snapappointments / bootstrap-select

:rocket: The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more.
https://developer.snapappointments.com/bootstrap-select/
MIT License
9.85k stars 2.72k forks source link

Can't toggleClass('open') on bootstrap-select #431

Closed emilkarolak closed 10 years ago

emilkarolak commented 10 years ago

I'm trying to expand bootstrap select with related label by adding class 'open' to it's container.

I put it in label click event in bootstrap-select.js - line 64 like this:

that.$newElement.toggleClass('open');

because I want select to expand instead of just focus.

I can toggle ANY class BUT 'open' - i can do 'openx' or so but not 'open' - no console error or anything - nothing happens.

Fiddle: http://jsfiddle.net/VrQ6P/ - line 64 in JavaScript window.

Please help.

caseyjhol commented 10 years ago

It's interfering with Bootstrap using toggleClass('open'), so you need to use stopPropagation. Then, use click instead of addClass to initiate setSize():

      $('label[for="' + id + '"]').click(function(e) {
          e.preventDefault();
          e.stopPropagation();
          that.$button.click();
      });

See it in action: http://jsfiddle.net/caseyjhol/VrQ6P/1/