bootstrap-combobox
bootstrap-combobox copied to clipboard
clearElement & clearTarget doesn't update selected option
In the source code, these two functions:
, clearElement: function () {
this.$element.val('').focus();
}
, clearTarget: function () {
this.$source.val('');
this.$target.val('');
this.$container.removeClass('combobox-selected');
this.selected = false;
}
Don't actually clear the selected value from the combobox. I know that we could just do a $el.val('') but I wanted to make this fix a part of core.
I wanted to accomplish two things:
- Don't focus on the control when clearing programmatically
- clear all attributes (target, source, and element)
The fix is quite minor, here's my solution:
, clear: function(){
this.$element.val('');
this.$source.val('');
this.$target.val('');
this.$container.removeClass('combobox-selected');
this.selected = false;
}
Its very similar to clearTarget but also cleans up the ui in the same call. I don't want to break existing configurations so i opted to make a new clear
function.
Should clearTarget just be updated to include this line?
this.$element.val('');
Also, could we remove the .focus from clearElement?
, clearElement: function () {
this.$element.val('').focus();
}
It makes it awkward for us to clear the box but then get focus forced to the combobox and away from whatever it was pointed at previously, just my opinion.
I got some strange UX behaviour so i revised my clear function to doi a clear value and refresh:
this.$element.val('');
this.source = this.parse();
this.options.items = this.source.length;
and this seems to work nicely