0

I am trying to create an autocomplete function for the following jinja template in jquery derived from base.html.

Jinja template:

{% extends "base.html" %}
{% block title %}Renter Information{% endblock %}

{% block head %}
    {{ super() }}
    <link rel = "stylesheet" href = "{{ url_for('static', filename = 'css/form.css') }}">
{% endblock %}

{% block content %}
    {% block page_content %}
    {{ super() }}
    <h1>Rental Property Information Form</h1>
    <p>Fill out the below form and a CSV containing Listing Date, Property Type, Suburb, State, Postcode,
    Property Address, Weekly Rent, Annual Rent, Land Area (if applicable) and URL will be sent to your email address.</p>
    <br>
    {{ wtf.quick_form(form, novalidate=True) }}
    {% endblock %}
{% endblock %}

base.html:

{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}{% endblock %}
{% block head %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/base.css') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='housing-icon-9.jpg') }}" type="image/x-icon">
<link rel="icon" href="{{ url_for('static', filename='housing-icon-9.jpg') }}" type="image/x-icon">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
{% endblock %}

{% block content %}
<div class="container">
    {% block page_content %}
    {% for message in get_flashed_messages() %}
    <div class="alert no results">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        {{ message }}
    </div>
    {% endfor %}
    {% endblock %}
</div>
{% endblock %}

the form contains a text input of id 'suburbs' which I created the following autocomplete function in the script.js file:

$(document).ready(function () {

    $('#suburbs').autocomplete({
        source: ["Eastern Red", "Eastern Blue"],
        minlength: 2
    });
})

However I seem to get the following error message in console:

Autocomplete is not a function

This is my output in the network tab: Network results

I have read other answers suggesting that there may be conflicts between bootstrap and jquery and have tried including jquery.noConflict() in script.js but still get the Autocomplete is not a function error. Other answers suggested jquery.ui maybe missing or jquery.ui is being imported before jquery which is not the case here.

What am I doing wrong here and how do I fix it?

0 Answers0