event to tell when user typed their own value vs selecting a suggestion
See original GitHub issueIs there a way to get an event when the user “selects” the text that they have typed out, which is separate from the offered suggestions? I.e. user has typed ‘apple’, with provided suggestion ‘applesauce’; however user really wants to submit simply ‘apple’.
Originally I tried using the ‘change’ event for this:
}).on('typeahead:selected', function($e, datum) { // suggestion selected
console.log('selected: ' + datum['url']);
window.location = datum['url'];
}).on('change', function(e) { // user typed their own value
value = $('input.search-input').val();
window.location = '/search_path?search=' + encodeURIComponent(value);
});
but unfortunately ‘change’ also seems to fire when the user selects from the drop-down, so if the user types ‘apple’ and then clicks ‘applesauce’ there’s a kind of race condition where sometimes the form submits ‘apple’ and sometimes ‘applesauce’, depending on the speed of the remote.
Issue Analytics
- State:
- Created 10 years ago
- Reactions:4
- Comments:23 (4 by maintainers)
Top Results From Across the Web
html - Javascript - Check if suggestions are shown when ...
I'm trying to detect when a user types in an input with autocomplete, if the suggestions are being shown by the browser. For...
Read more >Event.preventDefault() - Web APIs | MDN
The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default ...
Read more >Site Search Suggestions - Nielsen Norman Group
When your users select from search suggestions rather than typing in their own complete query, they benefit because they:.
Read more >Create and edit pivot tables - Google Support
You can add pivot tables based on suggestions in Google Sheets or create them ... Create custom groups—Select the items you want to...
Read more >Microsoft Privacy Statement
Microsoft collects data from you, through our interactions with you and ... choose not to share personal data, features like personalization that use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I needed that event too, to display a warning when the user types a “custom” value. It feels pretty hacky looking into “private” data, but here’s my temporary solution:
which I then listen to as:
This works both when the users selects an existing item, or manually types it out.
@rprieto
$input.data('ttView')
is undefined, how do i define datum now?