{"id":7981,"date":"2015-11-14T09:34:04","date_gmt":"2015-11-14T09:34:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/14\/confirm-delete-modal-dialog-with-twitter-bootstrap-open-source-projects-twbs-bootstrap\/"},"modified":"2015-11-14T09:34:04","modified_gmt":"2015-11-14T09:34:04","slug":"confirm-delete-modal-dialog-with-twitter-bootstrap-open-source-projects-twbs-bootstrap","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/14\/confirm-delete-modal-dialog-with-twitter-bootstrap-open-source-projects-twbs-bootstrap\/","title":{"rendered":"Confirm delete modal\/dialog with Twitter bootstrap?-open source projects twbs\/bootstrap"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8feb0675d5ebf4c11ed13885347cc970?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>dfsq<\/strong><\/p>\n<p>For this task you can use already available plugins and bootstrap extensions. Or you can make your own confirmation popup with just <strong>3<\/strong> lines of code. Check it out.<\/p>\n<p>Say we have this links (note <code>data-href<\/code> instead of <code>href<\/code>) or buttons that we want to have delete confirmation for:<\/p>\n<pre><code>Delete record #23\n\n\n    Delete record #54\n\n<\/code><\/pre>\n<p>Here <code>#confirm-delete<\/code> points to a modal popup div in your HTML. It should have an &#8220;OK&#8221; button configured like this:<\/p>\n<pre><code>\n    \n        \n            \n                ...\n            \n            \n                ...\n            \n            \n                Cancel\n                Delete\n            \n        \n    \n\n<\/code><\/pre>\n<p>Now you only need this little javascript to make a delete action confirmable:<\/p>\n<pre><code>$('#confirm-delete').on('show.bs.modal', function(e) {\n    $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));\n});\n<\/code><\/pre>\n<p>So on <code>show.bs.modal<\/code> event delete button <code>href<\/code> is set to URL with corresponding record id.<\/p>\n<h3>Demo: http:\/\/plnkr.co\/edit\/NePR0BQf3VmKtuMmhVR7?p=preview<\/h3>\n<h2>Bootstrap 2.3<\/h2>\n<p>Here is an original version of the code I made when I was answering this question for Bootstrap 2.3 modal.<\/p>\n<pre><code>$('#modal').on('show', function() {\n    var id = $(this).data('id'),\n        removeBtn = $(this).find('.danger');\n    removeBtn.attr('href', removeBtn.attr('href').replace(\/(&amp;|\\?)ref=\\d*\/, '$1ref=' + id));\n});\n<\/code><\/pre>\n<h3>Demo for Bootstrap 2.3: http:\/\/jsfiddle.net\/MjmVr\/1595\/<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>dfsq 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 of href) or buttons that we want to have delete confirmation for: Delete record #23 Delete record [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7981","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7981"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7981\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}