Currently, I am attempting to implement a simple popover feature using a div component within a Jinja template that will be rendered by Flask. Despite my efforts, I am encountering difficulties in getting it to function correctly.
Within my 'layout.jinja2' file, the basic structure of the HTML page is defined:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.png') }}">
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>{{ title }}</title>
</head>
<body class="{{template}}">
<div class="container">
{% block content %}
{% endblock %}
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.js"
integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
crossorigin="anonymous"></script>
</body>
</html>
Additionally, I have created another Jinja file, 'page_2.jinja', which extends the layout and includes a navigation bar with the desired dropdown menu:
% extends "layout.jinja2" %}
{% block content %}
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container-fluid">
<a class="navbar-brand" href="/">My Page</a>
<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav me-auto">
{% if current_user.is_authenticated %}
{% for app in current_user.app_permissions %}
{% if app == 'settings' %} {% continue %} {% endif %}
<li class="nav-item">
<a class="nav-link active" href="{{ url_for(get_app_url(app)) }}">{{ app.capitalize() }}</a>
</li>
{% endfor %}
{% endif %}
</ul>
<ul class="navbar-nav me-right">
{% if current_user.is_authenticated %}
<div>
<img id="menu" src="/assets/user_icon.png" data-bs-toggle="popover" data-bs-trigger="focus" data-bs-content="nav_dropdown">
</div>
{% else %}
<form class="d-flex" method="POST" action="/login">
<input class="form-control me-sm-2" type="email" name="email" placeholder="email">
<input class="form-control me-sm-2" type="password" name="password" placeholder="password">
<button class="btn btn-secondary my-2 my-sm-0" type="submit">Login</button>
</form>
{% endif %}
</ul>
</div>
</div>
</nav>
<div role="tooltip" x-placement="bottom" class="fade show popover bs-popover-bottom"
id="nav_dropdown" data-popper-reference-hidden="false" data-popper-escaped="false"
data-popper-placement="bottom" style="position: absolute; inset: 0px auto auto 0px; transform: translate(1413px, 52px);">
<ul class="list-group">
<a href="/settings" data-rr-ui-event-key="/settings" class="list-group-item">Settings</a>
<a href="/logout" data-rr-ui-event-key="/logout" class="list-group-item">Logout</a>
</ul>
</div>
<script type="text/javascript">
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl)
})
</script>
{% endblock %}
Despite setting up the structure for the popover as per Bootstrap documentation, I am encountering an error when trying to enable it using the provided script in 'page_2.jinja':
page_2:67 Uncaught ReferenceError: bootstrap is not defined
At this point, I am unsure of where I am going wrong. Any assistance in resolving this issue would be greatly appreciated. This is the only instance where I require JavaScript on the site, and I opted for Bootstrap 5 to avoid potential conflicts with jQuery, especially since React is used on other pages.