Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!