Why only the first modal works?

Asked

Viewed 39 times

1

I have two forms, one to insert and the other to edit. These forms are in modals. The modals open when I click on the "edit" button, but the "insert" modal does not open and still hangs the page. I don’t know where I am going wrong.

From the tests I’ve done, I’ve verified that only the modal that comes first written in the code that works.

follows the code below:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
    <title>Olho de Deus - Contratos</title>
    </head>
  <body>
    <button type="button" style="margin-right: 20px;" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalInsert">Novo contrato</button>
    <button type="button" class="btn btn-warning" style="margin-right: 20px;" data-bs-toggle="modal" data-bs-target="#modalUpdate">Editar contrato</button>
<!-- MODALS -->
<!-- UPDATE -->
<div class="modal fade" id="modalUpdate" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" style="width: 100%;">
  <form action="processaContratos.php?operacao=update" method="POST">
  <div class="modal-dialog modal-fullscreen" >
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="exampleModalLabel">Editar Contrato</h2>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <input type="hidden" name="id" id="id_update">
        <h5>Contrato inicial</h5>
        <hr>
        <div class="form-floating">
          <input type="text" min="1" style="width: 800px;" required class="form-control" id="contratada_update" name="contratada" placeholder="Contratada">
          <label for="bloco">Contratada</label><br>
        </div>
        <div class="form-floating">
          <input type="text" min="1" style="width: 800px;" required class="form-control" id="objeto_update" name="objeto" placeholder="Objeto">
          <label for="bloco">Objeto</label><br>
        </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fechar</button>
        <button type="submit" class="btn btn-primary">Salvar alterações</button>
      </div>
    </div>
  </div>
  </form>
</div>
<!-- INSERT -->
<div class="modal fade" id="modalInsert" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" style="width: 100%;">
  <form action="processaContratos.php?operacao=insert" method="POST">
  <div class="modal-dialog modal-fullscreen">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="exampleModalLabel">Adicionar novo Contrato</h2>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        
        <h5>Contrato inicial</h5>
        <hr>
        <div class="form-floating">
          <input type="text" min="1" style="width: 800px;" required class="form-control" id="contratada_insert" name="contratada_insert" placeholder="Contratada">
          <label for="bloco">Contratada</label><br>
        </div>
        <div class="form-floating">
          <input type="text" min="1" style="width: 800px;" required class="form-control" id="objeto_insert" name="objeto_insert" placeholder="Objeto">
          <label for="bloco">Objeto</label><br>
        </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fechar</button>
        <button type="submit" class="btn btn-primary">Salvar alterações</button>
      </div>
    </div>
  </div>
  </form>
</div>
    
</body>
</html>

1 answer

1

Just add </div> before the comment Insert.

probably this happened because the indentation is not very good, and it happened that the modal div does not close and "eat" the other modal along.

below is your code with the correct indentation.

I hope I helped Allan

<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
  <title>Olho de Deus - Contratos</title>
</head>

<body>
  <button type="button" style="margin-right: 20px;" class="btn btn-primary" data-bs-toggle="modal"
data-bs-target="#modalInsert">Novo contrato</button>
  <button type="button" class="btn btn-warning" style="margin-right: 20px;" data-bs-toggle="modal"
data-bs-target="#modalUpdate">Editar contrato</button>
  <!-- MODALS -->
  <!-- UPDATE -->
  <div class="modal fade" id="modalUpdate" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"
style="width: 100%;">
<form action="processaContratos.php?operacao=update" method="POST">
  <div class="modal-dialog modal-fullscreen">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="exampleModalLabel">Editar Contrato</h2>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <input type="hidden" name="id" id="id_update">
        <h5>Contrato inicial</h5>
        <hr>
        <div class="form-floating">
          <input type="text" min="1" style="width: 800px;" required class="form-control" id="contratada_update"
            name="contratada" placeholder="Contratada">
          <label for="bloco">Contratada</label><br>
        </div>
        <div class="form-floating">
          <input type="text" min="1" style="width: 800px;" required class="form-control" id="objeto_update"
            name="objeto" placeholder="Objeto">
          <label for="bloco">Objeto</label><br>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fechar</button>
          <button type="submit" class="btn btn-primary">Salvar alterações</button>
        </div>
      </div>
    </div>
</form>
  </div>
  </div>
  <!-- INSERT -->
  <div class="modal fade" id="modalInsert" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"
style="width: 100%;">
<form action="processaContratos.php?operacao=insert" method="POST">
  <div class="modal-dialog modal-fullscreen">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="exampleModalLabel">Adicionar novo Contrato</h2>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">

        <h5>Contrato inicial</h5>
        <hr>
        <div class="form-floating">
          <input type="text" min="1" style="width: 800px;" required class="form-control" id="contratada_insert"
            name="contratada_insert" placeholder="Contratada">
          <label for="bloco">Contratada</label><br>
        </div>
        <div class="form-floating">
          <input type="text" min="1" style="width: 800px;" required class="form-control" id="objeto_insert"
            name="objeto_insert" placeholder="Objeto">
          <label for="bloco">Objeto</label><br>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fechar</button>
          <button type="submit" class="btn btn-primary">Salvar alterações</button>
        </div>
      </div>
    </div>
</form>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW"
crossorigin="anonymous"></script>
</body>

</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.