Solution 1 :

on the Manage Employees button you are setting data-bs-toggle and data-bs-target, which should be data-toggle and data-target. Besides that you have to specify your target in data-target, you are defining a modal that doesn’t exist (#mymodal doesn’t exist in your code, that’s why nothing happens).

Here is a working sample with your code:

    <!DOCTYPE html>
      <html>
  <head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  <body>
  {% extends 'base.html' %}
{% include 'header.html' %}

{% block title %} Home {% endblock %}

{% block body %}
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <div class="bg-light p-3">
          <h2>Manage <b>Employees </b> <button type="button" class="btn btn-success float-end" data-toggle="modal" data-target="#mymodal">Add New Employees</button> </h2>
        {% with messages = get_flashed_messages() %}
        {% if messages %}

        {% for message in messages %}
        <div class="alert alert-success alert-dismissable" role="alert">
          <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
          <span aria-hidden="true">x</span>
          </button>
        {{message}}
        </div>
        {% endfor %}

        {% endif %}
        {% endwith %}

  <table class="table table-hover table-striped">
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Email</th>
      <th>Phone</th>
      <th>Action</th>
    </tr>
    {% for row in employee %}
    <tr>
      <td>{{row.id}}</td>
      <td>{{row.name}}</td>
      <td>{{row.email}}</td>
      <td>{{row.phone}}</td>
      <td>
        <a href="/update/{{row.id}}" class="btn btn-warning btn-xs" data-toggle="modal" data-target="#modaledit{{row.id}}">Edit</a>
        <a href="/delete/{{row.id}}" class="btn btn-danger btn-xs" onclick="return confirm('Are You Sure To Delete ?')">Delete</a>
      </td>
    </tr>

<!-- Modal Add Employee-->
<div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Add new Employee</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        Create your html form here ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Add New Employee</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal Edit Employee-->
<div class="modal fade" id="modaledit{{row.id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle2">Modal Edit</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        Modal Edit Body
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Edit Employee</button>
      </div>
    </div>
  </div>
</div>
</table>
    </div>
    </div>
  </div>
</div>
{% endblock %}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  </body>
</html>

By the way, you have an error on your code after your class row, you have class “col md-12″ which should be class=”col-md-12”. (missing the equals and hyphen sign).

More information about modals can be found here: https://getbootstrap.com/docs/4.0/components/modal/

Hope it helps! 🙂

Solution 2 :

I did solved it by placing the Add New Employee model code just below the Add New Employee button code…

Problem :

I have this management page that lists my employees from my sqlite database, but when I click Add New Employees, nothing happens, and I don’t get an error message as well…

I went over Bootstrap5 documentation to make sure I didn’t misspell anything but still stuck…

enter image description here

{% extends 'base.html' %}
{% include 'header.html' %}

{% block title %} Home {% endblock %}

{% block body %}
  <div class="container">
    <div class="row">
      <div class "col md-12">
        <div class="bg-light p-3">
          <h2>Manage <b>Employees </b> <button type="button" class="btn btn-success float-end" data-bs-toggle="modal" data-bs-target="#mymodal">Add New Employees</button> </h2>
        {% with messages = get_flashed_messages() %}
        {% if messages %}

        {% for message in messages %}
        <div class="alert alert-success alert-dismissable" role="alert">
          <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
          <span aria-hidden="true">x</span>
          </button>
        {{message}}
        </div>
        {% endfor %}

        {% endif %}
        {% endwith %}

  <table class="table table-hover table-striped">
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Email</th>
      <th>Phone</th>
      <th>Action</th>
    </tr>
    {% for row in employee %}
    <tr>
      <td>{{row.id}}</td>
      <td>{{row.name}}</td>
      <td>{{row.email}}</td>
      <td>{{row.phone}}</td>
      <td>
        <a href="/update/{{row.id}}" class="btn btn-warning btn-xs" data-toggle="modal" data-target="#modaledit{{row.id}}">Edit</a>
        <a href="/delete/{{row.id}}" class="btn btn-danger btn-xs" onclick="return confirm('Are You Sure To Delete ?')">Delete</a>
      </td>
    </tr>

<!-- Modal Add Employee-->

<!-- Modal Edit Employee-->

    </div>
  </div>
</div>
{% endblock %}

Comments

Comment posted by BlueSky Trading

I tried the same code but still nothing happens, I was on bootstrap5 and switched to 4, and again, the page is static and nothing pops-up… The Add New Employee code wasn’t added dur to the forum limitation on text/code ratio… How can I share the full code with you?

By