I’m trying to implement $(‘textarea-selector’).textcomplete method from https://github.com/ranvis/jquery-textcomplete/blob/master/jquery.textcomplete.js in Djnago Textarea widget.
django/forms/templates/django/forms/widgets/textarea.html
{% load static %}
<textarea name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>
{% if widget.value %}{{ widget.value }}{% endif %}</textarea>
<script src="js/tasks/jquery-1.10.2.min.js"></script>
<script src="js/tasks/jquery.textcomplete.min.js"></script>
<script type='text/javascript'>
$('#id_{{ widget.name }}').textcomplete([
{
words: ['select', 'from', 'fct_table1', 'fct_table2', 'where', 'column1', 'column2'],
match: /\b(\w{2,})$/,
search: function (term, callback) {
callback($.map(this.words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
index: 1,
replace: function (word) {
return word + ' ';
}
}
])
</script>
But get errors:
At the same time if I do the same in simple html file everything works well:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery-1.10.2.js"></script>
<script src="jquery.textcomplete.js"></script>
</head>
<body>
<textarea class="textarea" id="textarea" rows="4" cols="50">...</textarea>
<script>
$('.textarea').textcomplete([
{ // tech companies
words: ['select', 'from', 'fct_table1', 'fct_table2', 'where', 'column1', 'column2'],
match: /\b(\w{2,})$/,
search: function (term, callback) {
callback($.map(this.words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
index: 1,
replace: function (word) {
return word + ' ';
}
}
]);
</script>
</body>
</html>
How to make the script work inside Django?strong text
>Solution :
<script src="{% static 'js/tasks/jquery-1.10.2.min.js' %} "></script>
Do this for all external scripts.

