jqueryui / autocomplete: search for term if enter is pressed without using autocomplete tag
I'm using jqueryui's autocomplete widget (ui v1.8.4) as a helping tool for a sitesearch. Withou开发者_运维知识库t autocomplete the user types in his query, presses enter or search-button and get the results on result-page.
Autocomplete should work as addition while the user types. ... but if i type in a searchterm, i get the list from autocomplete. but now i have to choose one item of it instead of just hitting enter to get to the results page, as i have done without autocomplete.
$("#searchForm input").autocomplete({ source: "/suche", minLength: 3, delay: 100 });
I have jQuery UI autocomplete for a similar usecase: quick results as you type, full result page if you press enter.
You could probably change your code like so:
$("#searchForm input").autocomplete({ source: "/suche", minLength: 3, delay: 100 }).keydown(function(e){
if (e.keyCode === 13) {
$(this).closest('form').trigger('submit');
}
});
Which will submit the parent form of your search box. But obviously you could place any kind of custom logic in there.
精彩评论