Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
Flask add modal to ask before deleting. How to get working?

In my Flask APP i have a page with a link to delete: Is inside a table each row have this id, here I am sending the ID (that normaly I use to delete):

   <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" id="submits" onclick="send_to_modal('{{post.id}}')">
  Borrar
  </button>

Here is my javascript:

function send_to_modal(id){
    document.getElementById("exampleModalLabel").innerHTML = id;

};

The modal:

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">        </button>
      </div>
      <div class="modal-body">

        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success" onclick="modal_a_funccion()">SI</button>
        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">NO</button>
      </div>
    </div>
  </div>
</div>

I don´t know how to send the ID to another function that is charged to delete the specified data:

This is my function that works correcty and delete the data giving the ID:

function modal_a_funccion(id){
        console.log("Solicitando un report para: "+id);
        //fetch('/report/' + olt_hostname).then(function(response) {
        fetch('/task/report_celery/' + id).then(function(response) {
                response.json().then(function(data) {
                    for (var x of data.ip) {
                        console.log("REPORT_fetch recibe (IP): " +x.ip_oob)
                        console.log("REPORT_fetch recibe (ESTADO): " +x.estado)

                    };
                });
            });
    };

I would like to know how to to it.

What I intend to do is add a modal to ask the user for confirmation whether or not to delete. I can't find a way to pass the Id to the function that is in charge of doing the deletion. I would like to know how to do it. Thank you so much.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

A possible solution (in a different way)

  1. When user clicks on delete for a row, add a class e.g. to_delete. Then display the modal popup asking if user wants to go ahead with the delete or not.

  2. If user says no, close the modal and remove the class again

  3. If user says yes, call the delete function

For 3, you do something like

    // Find the element that user has marked for delete
    const element = document.querySelect(".to_delete")
    const id = element.id;

For 2, you do something like

   // Find the element that user has marked for delete and remove the delete mark
   document.querySelect(".to_delete").classList.remove("to_delete")
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda