On focus out of autocompletes clear value if not selected option (to be reviewed)

This commit is contained in:
apapachristou 2020-11-25 18:08:51 +02:00
parent 06f156c687
commit 2f61e47139
2 changed files with 16 additions and 0 deletions

View File

@ -201,6 +201,10 @@ export class MultipleAutoCompleteComponent extends _CustomComponentMixinBase imp
if (event.keyCode !== ENTER && (event.keyCode < 37 || event.keyCode > 40)) {
this._inputSubject.next(this.inputValue);
}
// if (event.keyCode !== ENTER && (event.keyCode < 37 || event.keyCode > 40) && event.keyCode !== COMMA) {
// this._inputSubject.next(this.inputValue);
// }
}
public onKeyDown(event) {
@ -232,6 +236,12 @@ export class MultipleAutoCompleteComponent extends _CustomComponentMixinBase imp
if (this.inputValue && this.inputValue.length > 1 && this.autocomplete.options && this.autocomplete.options.length > 0 && this.autoSelectFirstOptionOnBlur) {
this.optionSelectedInternal(this.autocomplete.options.first.value);
}
// Clear text if not an option
if (this.inputValue && this.inputValue.length > 1) {
this.inputValue = '';
document.getElementById((<HTMLInputElement>$event.target).id).focus();
}
}

View File

@ -242,6 +242,12 @@ export class SingleAutoCompleteComponent extends _CustomComponentMixinBase imple
this.inputValue = this._displayFn(this.autocomplete.options.first.value);
this.optionSelectedInternal(this.autocomplete.options.first.value);
}
// Clear text if not an option
else if (this.inputValue && this.inputValue.length > 1) {
this.inputValue = '';
document.getElementById((<HTMLInputElement>$event.target).id).focus();
}
}
onChange = (_: any) => { };