danielfarrell / bootstrap-combobox

A combobox plugin that works with twitter bootstrap
849 stars 328 forks source link

Combobox not selecting value in dropdown list. #243

Open lakipolitis opened 7 years ago

lakipolitis commented 7 years ago

I was experiencing an issue where the jQuery this.$source.val(this.map[val]).trigger('change');

was not forcing the select to actually highlight the option as selected. I noticed it on the demo as well. I'm using Chrome 57.0.2987.133

I changed that line of code (not nearly as clean as yours) to this:

      var v = this.map[val];
      this.$source.children().each(function () {
          if ($(this).val() == v) {
              $(this).attr('selected', 'selected');
          }
      });

And it's working nicely.

lakipolitis commented 7 years ago

As a note, I forgot to attach the change trigger and wasn't getting PostBack values in ASP.net. So I added it back and everything worked perfectly. Code now looks like this:


      var v = this.map[val];
      this.$source.children().each(function () {
          if ($(this).val() == v) {
              $(this).attr('selected', 'selected');
          }
      });
      this.$source.trigger('change');