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.
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.
Syntax: $("TagId"). autocomplete({ source : itemList // List of Words. })
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.
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.
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
}
You can also find the autocomplete behavior attached to an input element by following line of code:
if ($('Selector').data('autocomplete')) {
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With