danielfarrell / bootstrap-combobox

A combobox plugin that works with twitter bootstrap
847 stars 327 forks source link

Emptying and refilling combo values causes incorrect icon and sometimes cannot clear all values #212

Open Vbahole opened 8 years ago

Vbahole commented 8 years ago

I build 3 combos but i only fill the first in mvc. then on the client i use ajax to fill the other two as they are selected on change. But i'm having issues with the X icon showing up and also emptying the combos when there are change events to prior (uphill) combos. If i fill the select client side the combo will not refresh until i call: .data('combobox').refresh(); but after i call that the icon on the right side turns to an X - which indicates that a value has been selected, instead of a down carat. if i don't call refresh the values will not change at all. if i call .empty() on an established combo it doesn't clear the values. But if i add a single, non-null, new value then they will be cleared and the new single value is present

Scott64 commented 8 years ago

I'm pretty late to the party, but what you're doing sounds a lot like what I'm doing. Here's what I did, and it seems to work fine.

select.combobox('refresh'); select.combobox('clearElementNoFocus'); //Make the Xs go away select.combobox('clearTarget'); //Clear the field of its value select.trigger('change'); //Trigger a change event in case there are other fields dependent upon this field's value that will now also need to be cleared. This one is more specific to my scenario and doesn't actually have anything to do with combobox

Note that "clearElementNoFocus" is just a copy of "clearElement" I made that doesn't give focus to the cleared element because I sometimes have up to 5 fields being cleared out because of a single option that changed.