jQuery-Autocomplete icon indicating copy to clipboard operation
jQuery-Autocomplete copied to clipboard

Problem with minChars: 0

Open Aleksandr-ru opened this issue 6 years ago • 4 comments

Here is the situation: I need to get some suggestions when empty input is focused, so I used this options:

$('#suggest').autocomplete({
	minChars: 0,
	serviceUrl: '/some/ajax/request'
});

It works perfectly when input got focus and when I type first symbol, but later when I type more symbols it's not working (and there is no more requests in network tab in the browser). The problem occurs in latest Firefox and Chrome. It seems to be related to caching results because using noCache: true helps. Here is my workaround:

$('#suggest').autocomplete({
	noCache: true,
	minChars: 0,
	serviceUrl: '/some/ajax/request'
});

It looks like a bug because caching not works (or works wrong) with minChars: 0.

Aleksandr-ru avatar Aug 29 '17 13:08 Aleksandr-ru

If you find an issue please feel free submit a pull request for the fix. If you can share with me sample where this could be reproduced, I could take a look at it.

tkirda avatar Aug 29 '17 13:08 tkirda

There is not so easy to share the sample, but it should be reproducible on any suggestion with ajax and minChars: 0

Aleksandr-ru avatar Aug 29 '17 14:08 Aleksandr-ru

i have the same issue with minChars: 1. If the backend return zero results on an empty query (one char in my case), the query string will be marked as "bad" and every query string with a bad query will be prevented.

In your case "" is a prefix of every(!) sting.

"whatever".indexOf("") === 0 (line 605) is always true.

In my case "b" return 0 result, so "bad" will not be queried. noCache: true will prevent marking queries as bad.

volkerrichert avatar Apr 06 '18 14:04 volkerrichert

you may also set

preventBadQueries: false instead of disabling cache

volkerrichert avatar Apr 06 '18 14:04 volkerrichert