Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: $(...).autocomplete is not a function

I am getting the error TypeError: $(...).autocomplete is not a function when using the following code inside a Drupal module.

jQuery(document).ready(function($) {         $("#search_text").autocomplete({             source:results,             minLength:2,             position: { offset:'-30 0' },               select: function(event, ui ) {                      goTo(ui.item.value);                     return false;             }             });  }); 

jQuery is definitely loaded, and I have tried using a different variable for $ - any ideas what else might be the problem?

(Edit) Drupal specific answer for autocomplete:

drupal_add_library('system', 'ui.autocomplete'); 
like image 953
rix Avatar asked Apr 30 '13 13:04

rix


People also ask

How to fix autocomplete is not a function In jQuery?

To solve the "$(...). autocomplete is not a function" jQuery error, make sure to load the jQuery library before loading the jQuery UI library. The libraries have to be loaded only once on the page, otherwise the error is thrown.

Is not a function error in jQuery?

on if not a function" jQuery error occurs for 2 main reasons: Loading an old version of the jQuery library that doesn't support the on function. Loading a library that overrides the value of the dollar sign $ variable.

Is not a function Typeerror is not a function?

This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.

Is not defined in jQuery?

You may experience the “jQuery is not defined error” when jQuery is included but not loaded. Make sure that it's loaded by finding the script source and pasting the URL in a new browser or tab. The snippet of text you should look for to find the URL to test.


1 Answers

you missed jquery ui library. Use CDN of Jquery UI or if you want it locally then download the file from Jquery Ui

<link href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="Stylesheet"> <script src="YourJquery source path"></script> <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" ></script> 
like image 149
Ravi Gadag Avatar answered Oct 05 '22 19:10

Ravi Gadag