danielfarrell / bootstrap-combobox

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

I think the parse method needs an else at the end #235

Open weisborg opened 7 years ago

weisborg commented 7 years ago

There isn't anything currently when calling refresh(which calls parse) to clear the current selection if the new options don't have a selected option or the value that was there isn't in the list anymore.

It needs something like this at the end:

this.map = map;
if (selected) {
    this.$element.val(selected);
    this.$target.val(selectedValue);
    this.$container.addClass('combobox-selected');
    this.selected = true;
}
else {
    this.$element.val('');
    this.$target.val('');
    this.$container.removeClass('combobox-selected');
    this.selected = false;
}
return source;
weisborg commented 7 years ago

The if (option.prop('selected')) probably also needs something that also compares the option text to the existing text of the combobox input to select it as well. I'm not sure how it would work or which would override the other though.

This piece didn't impact me much since I use Mustache to set a data-value in the select and after updating the select I then set the value of the select before calling refresh on the combo. To me, since refresh is building off the select it should get all details from the select, but if we add any other functionality I've been seeing requested like allowing values not in the list and such it would be needed.