'I keep getting this error in my django project and I have literally tried everything I could find on stackoverflow but nothing works
Error: Uncaught TypeError: $(...).autocomplete is not a function
included in base.html:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
autocomplete code reference: https://www.geeksforgeeks.org/implement-search-autocomplete-for-input-fields-in-django/
EDIT: its being used in a template where I have only one field and I have to show emails using the autocomplete feature. The template extends base.html
{% block custom_js %}
<script type="text/javascript">
$( function() {
var _emails = "{{ emails }}".split(',');
var availableTags = [];
$.each(_emails, function(index, value){
availableTags.push(value);
});
$( "#id_email" ).autocomplete({
source: availableTags
});
});
</script>
{% endblock custom_js %}
Solution 1:[1]
Solution for future reference:
I tried this and it worked for me.
https://forum.jquery.com/topic/uncaught-typeerror-catcomplete-is-not-a-function
Changed function() to function($) as suggested in the answer in the forum. I haven't included jquery elsewhere yet this error wasn't resolving.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mia22 |
