Hello,
I'm using your very nice component in a dictionary application. I'm trying to have the following behavior to the search field:
I've tried intercepting the enter key in the input to navigate to the search page but the enter event is also fired when the user selects a completion. I tried cancelling event and many other kludges to no avail.
Is this behavior a achievable?
Would wrapping Autosuggest in a <form> and attaching onSubmit to it solve your issue?
Indeed. I had forgotten all this was just some html. I works perfectly. Thanks!
I know this has been closed, but if anyone else wants to do this, you may run into an issue depending on how complicated your implementation is.
If you begin typing, retrieve some suggestions, use the arrow keys to select a suggestion, and press enter to select that item, you will end up firing two events in competition:
The problem can arise if you're using onSuggestionSelected to get a deeper value, such as going to a url associated with the suggestion but the other event is just trying to fire whatever is in the input field.
I solved this by making it so the input field was locked off when the user was selecting with the keyboard. It was a messy implementation.
In my case, I had to preventDefault the event in the onSubmit and onSuggestionSelected to accomplish the behavior I wanted.
Most helpful comment
Would wrapping
Autosuggestin a<form>and attachingonSubmitto it solve your issue?