Posted By

novastream on 09/13/13


Tagged

delete jquery removal confirmation bootstrap bootbox


Versions (?)

Bootbox confirmation


 / Published in: jQuery
 

URL: http://www.novastream.se

Just a little code snippet to use with Bootbox, when assigning an A element with the class "delete-data-title" or "delete-data-empty" a confirmation modal will appear.

"delete-data-title" requires the html5 data attribute (data-object)

"delete-data-empty" will just show a static message when you click on a "A" element and doesn't requires any html5 data attributes.

Just load the code after loading bootbox, inline or as a file...

  1. //CONFIRM REMOVAL WITH TITLE
  2. $("a.delete-data-title").click(function(e) {
  3. e.preventDefault();
  4. var object = $(this).attr('data-object');
  5. var location = $(this).attr('href');
  6. bootbox.confirm("Vill du verkligen radera "+object+"?", "Nej", "Ja", function(confirmed) {
  7. if(confirmed) {
  8. window.location.replace(location);
  9. }
  10. });
  11. });
  12.  
  13. //CONFIRM REMOVAL DEFAULT
  14. $("a.delete-data-empty").click(function(e) {
  15. e.preventDefault();
  16. var location = $(this).attr('href');
  17. bootbox.confirm("Vill du verkligen radera vald post?", "Nej", "Ja", function(confirmed) {
  18. if(confirmed) {
  19. window.location.replace(location);
  20. }
  21. });
  22. });

Report this snippet  

You need to login to post a comment.