Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you trigger autocomplete "select" event manually in jQueryUI?

I'm using jQueryUI autocomplete, and I have a function mapped to the select event, e.g.:

$("#someId").autocomplete({     source: someData,     select: function (event, ui) { ... },     focus: function (event, ui) { ... } }); 

I have a special case: The user has focused on an item in the autocomplete drop-down (but not selected it) and I need to trigger the select event manually from a different function. Is this possible? If so, how?

like image 452
Jon Lemmon Avatar asked Oct 03 '11 10:10

Jon Lemmon


People also ask

What is autocomplete select?

HTML | <select> autocomplete Attribute on: It is the default value. When the autocomplete attribute is set to on the browser will automatically complete the values based on which the user entered before.

What is the default value of appendTo option of autocomplete () method?

Option - appendTo By default its value is null. When the value is null, the parents of the input field will be checked for a class of ui-front.

How does jQuery autocomplete work?

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.


2 Answers

Here's what worked for me:

$(this).data('ui-autocomplete')._trigger('select', 'autocompleteselect', {item:{value:$(this).val()}}); 
like image 116
temuri Avatar answered Sep 28 '22 08:09

temuri


You could do:

$("#someId").trigger("autocompleteselect"); 
like image 44
Nicola Peluchetti Avatar answered Sep 28 '22 06:09

Nicola Peluchetti