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

Pressing Enter doesn't call onSelect #6

Closed
adam-lynch opened this issue Jan 26, 2015 · 8 comments
Closed

Pressing Enter doesn't call onSelect #6

adam-lynch opened this issue Jan 26, 2015 · 8 comments

Comments

@adam-lynch
Copy link

I can't even find 13 (the keycode for enter) anywhere in the code. It does put the item's text in the field, but I can't see where it does that.

@SimonSteinberger
Copy link

We try to keep the plugin as simple and efficient as possible. Therefore, the onSelect callback is only fired on mouse click/select.

From the docs:
"A callback function that fires when a suggestion is selected by mouse click."

AFAICS, the callback has just one use case: You can submit the form on select. That's how we use it on Pixabay. By doing that, the mouse click has an identical behavior like pressing enter on a regular form. As it is, the plugin doesn't interfere in the normal form field behavior. The form gets submitted when pressing enter. Additionally, you can bind all kinds of event handler on the input field directly.

So, it's intentional, but we might change this if it's important. It doesn't involve a lot of overhead, but some ... Closing the issue for now.

@adam-lynch
Copy link
Author

I don't think any of those options work for my use case. I want to get a callback whenever a suggestion is selected. It has nothing to do with submitting the form. If #8 is merged, then when you click a suggestion, onSelect will be called with the text and the suggestion. If you press enter to select (plenty of people would), then you get nothing, onSelect isn't called. I think it'll be trivial to add, I'll see can I create a PR in a minute.

@adam-lynch
Copy link
Author

See #9.

@SimonSteinberger
Copy link

Yes, it's simple to add and it wouldn't cause a lot of overhead. We would include this feature right away if a few people preferred to have it.

I think it can be useful and maybe it's even important to always fire the onSelect callback. But it's also important to keep the plugin as tiny as possible. There are quite a few suggester plugins available with lots and lots of options, but they usually come with the price of a huge code base, e.g. jQuery UI autocomplete: http://jqueryui.com/autocomplete/

We'll definitely think about it - and if others join in, we'll certainly include the feature!

@3ynm
Copy link

3ynm commented Feb 2, 2016

I think onSelect should always be triggered when something is selected, why not?

@havramar
Copy link

👍

@oshihirii
Copy link

+1 for onSelect being triggered by pressing Enter.

@oshihirii
Copy link

For those looking, the devbridge autocomplete plugin has this behaviour by default, I have put together heavily commented codepen demo here.

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

Successfully merging a pull request may close this issue.

5 participants