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

Submit on item select (enter) #54

Closed
sdillinger opened this Issue Jul 21, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@sdillinger

sdillinger commented Jul 21, 2015

If I arrow down to select an item and then hit enter I feel a submit event should be triggered. As it stands now I have to hit enter twice- once to bring the item to the top and then again to submit. I'm not sure I understand the use case where I'd hit enter on a item and want to do anything other than submit (?)

Is there a way to do this that I missing?

Thanks.

@running-coder

This comment has been minimized.

Owner

running-coder commented Jul 21, 2015

true, I've received that comment from other people too.. the goal behind it was to trigger a onclick callback and from there you decide what to do: manually submit or do other operation depending on your typeahead instance. Some people uses it as a form input to select a country so triggering submit if they press enter would submit the form even if the user is not finished filling it up. Unfortunately I cant make everyone happy but perhaps there is a better way to do this? to make this less confusing

@ThiefMaster

This comment has been minimized.

ThiefMaster commented Jul 21, 2015

I'm not sure I understand the use case where I'd hit enter on a item and want to do anything other than submit (?)

What if you have more fields in the form? You might expect enter to simply close the suggestions and put the selected value in the field.

@sdillinger

This comment has been minimized.

sdillinger commented Jul 21, 2015

Ahh. Ok. I understand the use case. How about adding submitOnEnter [t/f]? It would submit the list item if the user hit enter while focused on that item. If the input box has focus and the selection is not complete, but is hinted, it would submit the hinted item. Ex: app[le] would submit apple.

@running-coder

This comment has been minimized.

Owner

running-coder commented Jul 21, 2015

seems like a very reasonnable approach, it would allow people to easily do it without adding a callback.. my only concern with this extra option is that it can easily be done otherway without addind another option (I think we are closing to 25) perhaps having at least 2 callback examples (one with onClick and one with onNavigate) and add documentation would do it?

@sdillinger

This comment has been minimized.

sdillinger commented Jul 21, 2015

I guess that's your call. Your documentation is excellent. Very clear and precise. As a user I don't see additional options that are targeted and easy to explain as being a negative. Requiring callback code to implement the functionality is a de facto option, just a lot more obtuse and difficult to explain.

Having said all that, I'm +1 for option, but either way works for me.

@sdillinger

This comment has been minimized.

sdillinger commented Jul 23, 2015

I've played around with this a bit. Going with your suggestion it seems I can simply capture the onClickBefore event and trigger submit. This works except the item passed to the onSubmit callback is empty, which I guess makes sense. How can I populate the item?

Also- quick question. Why does right-arrow trigger onClick? It's not a click and it seems to be something that would be handled via onNavigate. I assume there is a good reason. Just curious what it is.

Thanks.

@running-coder

This comment has been minimized.

Owner

running-coder commented Jul 23, 2015

The onsubmit should receive the selected item object from the onclickbefore function and as you mentionned it is currently not (I've just spotted why)

regarding the right arrow (if your text carret is at the end of your string) triggers a click to select the item and I admit not thinking of any usecase where it should be doing otherwise. But you are totally right, the right arrow could easily be handled by the onNavigate callback and lead to a sumbit or a simple autocomplete if the programmer wants to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment