Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onHint tab doesn't work with custom lookup function #836

Open
Woet opened this issue Jan 26, 2022 · 2 comments
Open

onHint tab doesn't work with custom lookup function #836

Woet opened this issue Jan 26, 2022 · 2 comments

Comments

@Woet
Copy link

Woet commented Jan 26, 2022

Hi,

Thanks for the great library! I've been running into some issues with onHint tabbing throwing errors and I narrowed it down to it happening whenever a custom lookup function is being used. You can find a working test case here: https://jsfiddle.net/0g8w43a1/

This code works perfectly fine:

$("#object").autocomplete({
	onHint: true,
  
	lookup: ['foolish', 'footage', 'footing']
});

But this one throws an error when using tab to select the hint:

$("#function").autocomplete({
	onHint: true,
  
	lookup: function(query, done) {
  		done({
			suggestions: [
      				{ value: 'foolish' },
      				 { value: 'footage' },
        			{ value: 'footing' }
			]
		});
	}
});

And here is the actual error:

jquery.autocomplete.js:938 Uncaught TypeError: Cannot read properties of undefined (reading 'value')
    at Autocomplete.onSelect (jquery.autocomplete.js:938:58)
    at Autocomplete.select (jquery.autocomplete.js:866:18)
    at Autocomplete.selectHint (jquery.autocomplete.js:860:18)
    at Autocomplete.onKeyPress (jquery.autocomplete.js:408:30)
    at HTMLInputElement.<anonymous> (jquery.autocomplete.js:212:68)
    at HTMLInputElement.dispatch (jquery-3.6.0.min.js:2:43064)
    at HTMLInputElement.v.handle (jquery-3.6.0.min.js:2:41048)

Let me know if I can help in any way.

@tkirda
Copy link
Member

tkirda commented Feb 17, 2022

Feel free to submit a PR if you know what is the issue.

@Woet
Copy link
Author

Woet commented Feb 17, 2022

There are a few dozen pull requests dating back for years that haven't received feedback nor have been merged, so I'm not sure if submitting a PR is useful. :)

For now, I've changed the selectHint version to the following which resolved the issue for me:

selectHint: function () {
	var that = this,
		i = $.inArray(that.hint, that.suggestions);

	i = Object.values(that.suggestions).findIndex(suggestion => suggestion.value == that.hint.value);

	that.select(i);
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants