0

I have a .jsp file on which I have a header that contains a button with id "modalFormButton", which when pressed must display a modal form. The code for the modal form is in another .jsp file so I am adding it dynamically. I already checked that if it is successfully calling the file with said content but it does not display the form. I also tried putting the form code in the same .jsp I called it from and it didn't work either.

PS: The modal form is contained within a div with an id of "agregarClienteModal". Also, I am using Bootstrap.

.jsp main file:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        
        <!-- Bootstrap CSS -->
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
        <title>JSP Page</title>
    </head>
    <body>
        <header class = "py-2 bg-info text-white">
            <div>
                <h1>
                    Clients
                </h1>
                <button type = "button" id = "modalFormButton" class="btn btn-primary btn-block data-toggle="modal" data-target="#agregarClienteModal">
                     Agregar Cliente
                </button>
            </div>
             <jsp:include page="addClientModalForm.jsp"/>
        </header>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
    </body>
</html>

Modal form code:

<div class="modal fade" id="agregarClienteModal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header bg-info text-white">
                <h5 class="modal-title">Agregar Cliente</h5> 
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
            </div>
            
            <form action="${pageContext.request.contextPath}/servlet?accion=insertar"
                  method="POST" class="was-validated">
                
                <div class="modal-body">
                    <div class="form-group">
                        <label for="nombre">Nombre</label>
                        <input type="text" class="form-control" name="nombre" required>
                    </div>
                    <div class="form-group">
                        <label for="apellido">Apellido</label>
                        <input type="text" class="form-control" name="apellido" required>
                    </div>
                    <div class="form-group">
                        <label for="email">Email</label>
                        <input type="email" class="form-control" name="email" required>
                    </div>
                    <div class="form-group">
                        <label for="telefono">Teléfono</label>
                        <input type="tel" class="form-control" name="telefono" required>
                    </div>
                    <div class="form-group">
                        <label for="saldo">Saldo</label>
                        <input type="number" class="form-control" name="saldo" required step="any">
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary" type="submit">Guardar</button>
                </div>    
            </form>
        </div>
    </div>
</div>
Androso
  • 9
  • 4

1 Answers1

2

The data- attributes have changes to data-bs- in Bootstrap 5...

<div>
   <h1> Clients </h1>
   <button type="button" id="modalFormButton" class="btn btn-primary btn-block" data-bs-toggle="modal" data-bs-target="#agregarClienteModal"> Agregar Cliente </button>
</div>

Demo

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624