Autocomplete presents a list of values when input is empty
I'm submitting a ... (check one with "x")
[x ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Plunkr Case (Bug Reports) Plunkr is not required. The bug can be reproduced on the PrimeNG demo page: https://www.primefaces.org/primeng/#/autocomplete
Current behavior If you type some characters and then delete all of them one by one (by pressing Backspace quickly enough so the dropdown list does not have the time to refresh) the Autocomplete presents a list of values which is relevant to the first character that was typed, even if the input is currently empty.
This behavior is not observed when the characters are selected and then deleted at once with either Backspace or Delete, or if characters are simply deleted with Backspace but slowly enough to allow the dropdown to refresh and present the relevant results.
Expected behavior The autocomplete should present no values when the input is empty.
Minimal reproduction of the problem with instructions Steps to reproduce using the "Basic autocomplete" on the demo page:
- Type 'AL' - the Autocomplete will present [Albania, Algeria]
- Double tap backspace (don't just hold it, since there's a delay after the first letter deletion) - after both letters are deleted the autocomplete presents a list of countries starting with 'A'.
A recording is available here: https://drive.google.com/file/d/0B__xPam6HZjwX2dzRzlTbjhESUU/view
Please tell us about your environment: OS: Debian GNU/Linux 8 (jessie) 64-bit
- Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Browser: Chrome 58.0.3029.110 (64-bit)
An easy fix is in completeMethod add an if:
search(event) {
if (event.query === '') {
this.results = [];
} else { .....
PS: No, it is not fixed. The problem is if you hold the delete key. It is an async problem, the last search is executed. To fix the issue just add:
if (this.timeout) {
clearTimeout(this.timeout);
}
in line 298 in autocomplete.ts autocompleteL298
Or move the clearTimeout out of the 'if(value.length >= this.minLength) {'
@cagataycivici Any news on this one? Should we invest in a PR to fix this?
Unable to replicate with latest PrimeNG, if the issue persists please create a new ticket with a test case reproducing the issue e.g. stackblitz or a github repo and it will be reviewed by our team once again.