Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/tom-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,21 @@ export default class TomSelect extends MicroPlugin(MicroEvent){
}
};

const input_invalid = () => {
if( self.isValid ){
self.isValid = false;
self.isInvalid = true;
self.refreshState();
}
}

addEvent(input,'invalid', input_invalid);
addEvent(document,'mousedown', doc_mousedown);
addEvent(window,'scroll', win_scroll, passive_event);
addEvent(window,'resize', win_scroll, passive_event);

this._destroy = () => {
input.removeEventListener('invalid',input_invalid);
document.removeEventListener('mousedown',doc_mousedown);
window.removeEventListener('scroll',win_scroll);
window.removeEventListener('resize',win_scroll);
Expand All @@ -405,14 +414,6 @@ export default class TomSelect extends MicroPlugin(MicroEvent){
delete settings.optgroups;
delete settings.options;

addEvent(input,'invalid', () => {
if( self.isValid ){
self.isValid = false;
self.isInvalid = true;
self.refreshState();
}
});

self.refreshItems();
self.close(false);
self.inputState();
Expand Down Expand Up @@ -765,15 +766,15 @@ export default class TomSelect extends MicroPlugin(MicroEvent){
*
*/
onInput(e:MouseEvent|KeyboardEvent):void {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh sorry, editor is removing trailing whitespace :(

if( this.isLocked ){
return;
}

const value = this.inputValue();
if( this.lastValue === value ) return;
this.lastValue = value;

if( value == '' ){
this._onInput();
return;
Expand Down Expand Up @@ -1455,14 +1456,14 @@ export default class TomSelect extends MicroPlugin(MicroEvent){

optgroup = option[self.settings.optgroupField] || '';
optgroups = Array.isArray(optgroup) ? optgroup : [optgroup];


for (j = 0, k = optgroups && optgroups.length; j < k; j++) {
optgroup = optgroups[j];

let order = option.$order;
let self_optgroup = self.optgroups[optgroup];
if( self_optgroup === undefined ){
if( self_optgroup === undefined ){
optgroup = '';
}else{
order = self_optgroup.$order;
Expand All @@ -1485,8 +1486,8 @@ export default class TomSelect extends MicroPlugin(MicroEvent){
active_option = option_el;
}
}
}
}

group_fragment.appendChild(option_el);
if( optgroup != '' ){
groups[optgroup] = group_order_i;
Expand Down