Bootbox Confirm Dialog problems

孤街醉人 提交于 2019-12-03 05:44:45

You may want to check the source on the "Confirm" link under "Basic Usage" on this page: http://bootboxjs.com/

Here's a snippet:

$("a.confirm").click(function(e) {
    e.preventDefault();
    bootbox.confirm("Are you sure?", function(confirmed) {
        console.log("Confirmed: "+confirmed);
    });
});

Assuming jQuery is available in the UI you're working on, I'd avoid using an onClick attribute in your anchor tags. Just my two cents.

I needed that too, but I changed a little few things... Take a look...

Add this function into your global "jQuery Ready" function like that:

$(document).on("click", "[data-toggle=\"confirm\"]", function (e) {
    e.preventDefault();
    var lHref = $(this).attr('href');
    var lText = this.attributes.getNamedItem("data-title") ? this.attributes.getNamedItem("data-title").value : "Are you sure?"; // If data-title is not set use default text
    bootbox.confirm(lText, function (confirmed) {
        if (confirmed) {
            //window.location.replace(lHref); // similar behavior as an HTTP redirect (DOESN'T increment browser history)
            window.location.href = lHref; // similar behavior as clicking on a link (Increments browser history)
        }
    });
});

And just add some "data-* attributes" to your button or link like that:

<a class="btn btn-xs btn-default" data-toggle="confirm" data-title="Do you really want to delete the record 123?" href="/Controller/Delete/123"><span class="fa fa-remove"></span> </a>

So... This way you can have a personalized question.. This is much more intuitive for your users...

Did you liked?!

See demo: jsfiddle

$(document).on("click", ".confirm-modal", function(e) {
    e.preventDefault();
    bootbox.confirm("Are You sure?", function(result) {
        if(result) {
            top.location.href = e.target.href;
        }
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!