I am using bootstrap confirmation plugin, and I have a table with a list of users. One of the columns has a delete button which goes to a link to delete the user, but before deleting the user I have a confirmation box which needs to be clicked. I want to just use one confirmation dialog that pops up for every button and I want to assign the link of the user id to the delete button.
Now the twist is that the whole table is within a form for multiple deletion as well. So I cant have individual forms for each delete button.
<table class="table table-bordered table-striped mb-none" id="datatable-default">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th class="center">Actions</th>
</tr>
</thead>
<tbody>
<tr role="row" class="even">
<td>1</td>
<td><a href="http://website.dev/globaladmin/users/7">jane doe</a></td>
<td>jane@gmail.com</td>
<td>
<a href="#" class="confirmation-callback" data-id="1" data-placement="left">
<i class="fa fa-trash-o"></i>
</a>
</td>
</tr>
<tr role="row" class="even">
<td>2</td>
<td><a href="http://website.dev/globaladmin/users/7">john doe</a></td>
<td>john@gmail.com</td>
<td>
<a href="#" class="confirmation-callback" data-id="2" data-placement="left">
<i class="fa fa-trash-o"></i>
</a>
</td>
</tr>
<tbody>
And here my js code:
$('.confirmation-callback').confirmation({
onConfirm: function() {
alert('You clicked: delete');
},
onCancel: function() {
alert('You clicked: cancel');
}
});
In the javascript I just want to get the data-id of the button that is calling the function, something like:
$(this).data(id);
Here is link to jsfiddle/full code: http://jsfiddle.net/mswyxp0u/