Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger jQuery Autocomplete manually

Tags:

I'm using jQuery UI Autocomplete with some AJAX (the data isn't pulled until after they stop typing). I would like to make it so once the data is found, Autocomplete will then pop-up as a search result. This works, however only when I start typing again (the dropdown doesn't trigger until I type because it's not initialized until after I stop typing).

My code:

var availableTags = [
    "Perl",
    "PHP",
    "Python",
    "Ruby"
];
$('input#mainSearchBox').autocomplete({
    source: availableTags,
        minLength: 0
});
    $('input#mainSearchBox').data('autocomplete').menu.active;

The last part was an attempt to activate autocomplete, but it fails.

like image 750
TheFrack Avatar asked Dec 03 '12 15:12

TheFrack


People also ask

How to trigger autocomplete in jQuery?

The jQuery UI Autocomplete change event is used to trigger when the search field is blurred and the value has changed. Syntax: Initialize the autocomplete with the change callback specified: $( ".

How does autocomplete work in jQuery?

In the process of searching a specific value, the jQuery UI autocomplete selection feature provides the user with some string suggestions for the input area which effectively saves time. The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.

What is jQuery ui autocomplete?

Advertisements. Auto completion is a mechanism frequently used in modern websites to provide the user with a list of suggestions for the beginning of the word, which he/she has typed in a text box. The user can then select an item from the list, which will be displayed in the input field.


1 Answers

The search method should do the trick:

$('input#mainSearchBox').autocomplete("search");

Fiddle

like image 71
Thorsten Avatar answered Sep 16 '22 15:09

Thorsten