Autocomplete minLength parameter not working

I am using the minLength parameter. however, suggestions are still being shown even when 1 character is entered into the search box. I would have expected nothing to be shown until at least 2 characters are entered.

What am I doing wrong here?

Thanks

Simon

Here is a snippet of my code:

autocomplete(’#<%=txtSearch.ClientID%>’,
{ hint: true }, {
source: autocomplete.sources.hits(index, { hitsPerPage: 20 }),
//value to be displayed in input control after user’s suggestion selection
displayKey: ‘sku’,
minLength: ‘2’,
//hash of templates used when rendering dataset
templates: {

Hey,

minLength should be a number, not a string. Could you try changing that?

Have a nice day!

It doesn’t work without the quotes either. I only added the quotes originally because it wasn’t working without them.

The minLength is an option of autocomplete itself, and not of a source:

var client = algoliasearch("latency", "6be0576ff61c053d5f9a3225e2a90f76");
var index = client.initIndex("contacts");

autocomplete(
	"#contacts",
	{
		hint: false,
		// should be here
		minLength: 3
	},
	[
		{
			source: autocomplete.sources.hits(index, { hitsPerPage: 5 }),
			displayKey: "name",
			templates: {
				suggestion: function(suggestion) {
					return suggestion._highlightResult.name.value;
				}
			}
		}
	]
);

see https://codepen.io/Haroenv/pen/oGRYpQ/

1 Like