Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting jQuery UI autocomplete

How can I detect whether or not an input box is currently a jQuery UI autocomplete? There doesn't seem to be a native method for this, but I'm hoping there is something simple like this:

if ($("#q").autocomplete)
{
  //Do something
}

That conditional, however, seems to always return true.

like image 351
Soldarnal Avatar asked Oct 31 '08 20:10

Soldarnal


People also ask

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.

How can create autocomplete search box in jQuery?

Syntax: $("TagId"). autocomplete({ source : itemList // List of Words. })

Which are jQuery ui widgets?

a jQuery UI widget is a specialized jQuery plug-in. Using plug-in, we can apply behaviours to the elements. However, plug-ins lack some built-in capabilities, such as a way to associate data with its elements, expose methods, merge options with defaults, and control the plug-in's lifetime.

How display image in jQuery ui autocomplete textbox in PHP?

Here we will make autocomplete textbox, in which make list pre-populated search result with image. This feature we will make by add custom html tag in jQuery UI autocomplete method by add _renderItem. Here we will use __renderItem method, by using this method we will add custom HTML code in autocomplete textbox.


3 Answers

if ($("#q").hasClass("ac_input")) {
    // do something
}

UPDATE

The class name in the JQuery UI autocomplete widget is now 'ui-autocomplete-input' so that code would be:

if ($("#q").hasClass("ui-autocomplete-input")) {
    // do something
}
like image 166
Randy Avatar answered Sep 30 '22 15:09

Randy


You can also find the autocomplete behavior attached to an input element by following line of code:

if ($('Selector').data('autocomplete')) {
}
like image 23
Matloob Ali Avatar answered Sep 30 '22 15:09

Matloob Ali


If the autocomplete jquery UI plugin is already included for the page and you just want to check to see if a particular (input) element has been setup with autocomplete function, you can use the official API method as shown below:

if ($("#q").autocomplete("instance")) {
    console.log("autocomplete already setup for #q");
} else {
    console.log("NO autocomplete for #q");
}

More details can be found at http://api.jqueryui.com/autocomplete/#method-instance

like image 26
Robin Avatar answered Sep 30 '22 16:09

Robin