简体   繁体   中英

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. Without 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM