Delete confirmation popup

229 views
Skip to first unread message

Winter Kryz

unread,
Mar 27, 2017, 7:49:59 PM3/27/17
to web2py-users
Hello Everybody,

I hope someone can help me, I have a table full of records from a data base, each row has a delete button so what I want to do is to show a "Yes/No" Javascript popup to confirm the delete action.

So far what I did is:

 *** controller ***
def Person():
    person = db(db.Person.id>0).select()
    class Virtual(object):
        def button(self):
          XML(A(SPAN(_class='glyphicon glyphicon-remove'),_id="delete",_onclick='myFunction()',_class='btn btn-default fechar Jview btn-xs')),_class='btn-group btn-group-justified JpositionA')
            return bts
    person.setvirtualfields(campos_virtual = Virtual())
    return dict(formListar=person)

*** View ***
<script>
function myFunction() {
    $('#myModal').modal('show');
    return false;
};

 function myFunctiondelete() {
 };
</script>

    <table id="tablaGenerica" class="tablaC table-striped hover cell-border" cellspacing="0" width="100%" >
<thead>
    <tr>
        <th>Name</th>
        <th>Surname</th>
        <th></th>
    </tr>
    <tbody>
        {{for person in formListar:}}
            <tr>
                <td>{{=person.Person.name}}</td>
                <td>{{=person.Person.surname}}</td>
                <td class="options">{{=person.campos_virtual.buttons}}</td>
            </tr>
    </tbody>
       {{pass}}
</thead>
</table>
<div id="myModal" class="modal fade">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
       <h4 class="modal-title">Confirmation </h4>
      </div>
      <div class="modal-body">
       <p>
          Are you sure you want to delete?
          </p>
      </div>
      <div class="modal-footer">
          <div class="col-md-6 col-md-offset-3 ">
        <button type="button" id="cancel" class="botones btn btn-secondary" data-dismiss="modal">No</button>
        <button type="button" id="warning" class="botones btn btn-warning" onclick="myFunctiondelete()";>Yes<span class="glyphicon glyphicon-remove"></span> </button>
         </div>

Basically, everytime I click on the button I defined on the controller it calls a function "myFunction()" which shows a Javascript modal with the Yes/No options. When I click on "Yes" it doesn't do anything because I don't know how to pass the id of that particular record.

Anyone knows an easier method or how can I pass the id of that particular record?

Thanks

Marlysson Silva

unread,
Mar 28, 2017, 9:09:04 AM3/28/17
to web2py-users
Have you tried the ajax function() from web2py ?

It use the callback function on controller and the data( id by example ) , and the callback receive this data and process them ( make search and delete it ) .

Winter Kryz

unread,
Mar 28, 2017, 2:39:19 PM3/28/17
to web2py-users
You mean the onclick: function() ?

Marlysson Silva

unread,
Mar 28, 2017, 6:54:06 PM3/28/17
to web2py-users
No. This http://web2py.com/books/default/chapter/29/11/jquery-and-ajax#The-ajax-function


I suggest you put a attribute "data-id" in your delete button and when you click them get the "data-id" attribute pass to ajax_function that run some function in controller.
Reply all
Reply to author
Forward
0 new messages