I have an HTML table of rows tied to database rows. I'd like to have a "delete row" link for each row, but I would like to confirm with the user beforehand.
Is there any way to do this using the Twitter Bootstrap modal dialog?
I have an HTML table of rows tied to database rows. I'd like to have a "delete row" link for each row, but I would like to confirm with the user beforehand.
Is there any way to do this using the Twitter Bootstrap modal dialog?
You can try more reusable my solution with callback function. In this function you can use POST request or some logic. Used libraries: JQuery 3> and Bootstrap 3>.
https://jsfiddle.net/axnikitenko/gazbyv8v/
Html code for test:
Javascript:
GET recipe
For this task you can use already available plugins and bootstrap extensions. Or you can make your own confirmation popup with just 3 lines of code. Check it out.
Say we have this links (note
data-href
instead ofhref
) or buttons that we want to have delete confirmation for:Here
#confirm-delete
points to a modal popup div in your HTML. It should have an "OK" button configured like this:Now you only need this little javascript to make a delete action confirmable:
So on
show.bs.modal
event delete buttonhref
is set to URL with corresponding record id.Demo: http://plnkr.co/edit/NePR0BQf3VmKtuMmhVR7?p=preview
POST recipe
I realize that in some cases there might be needed to perform POST or DELETE request rather then GET. It it still pretty simple without too much code. Take a look at the demo below with this approach:
Demo: http://plnkr.co/edit/V4GUuSueuuxiGr4L9LmG?p=preview
Bootstrap 2.3
Here is an original version of the code I made when I was answering this question for Bootstrap 2.3 modal.
Demo: http://jsfiddle.net/MjmVr/1595/
I can easily handle this type of task using bootbox.js library. At first you need to include bootbox JS file. Then in your event handler function simply write following code:
Offical bootboxjs site
When its comes to a relevantly big project we may need something re-usable. This is something I came with with help of SO.
confirmDelete.jsp
reusingPage.jsp
Note: This uses http delete method for delete request, you can change it from javascript or, can send it using a data-attribute as in data-title or data-url etc, for support any request.
If using SpringBoot, Thymeleaf, Bootstrap 4.3.1 and JQuery 3.4.1 here are my two cents.
The JQuery piece:
Somewhere in your html table:
and at the bottom of your html:
And in your controller:
For a full example with other bootstrap modal actions, refer here.