Thishani Lucas Thishani Lucas - 6 months ago 127
jQuery Question

can i disable sweet alert js buttons?

I want to disable the button displayed in sweet alerts so that my user cannot click the button again and again. i have attached the screen shot of the alert hear

i want to disable the confirmation button(i don't want the alert to be close), this is my sweet alert code.

swal({
title: "Are you sure?",
text: "You want to add this discount?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Continue",
cancelButtonText: "Cancel",
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm){
if (isConfirm) {
document.getElementById('message_error_new_discount').innerHTML = '';
$.post('./CURL/addNewDiscount.php',JSON.stringify({
"code": discount_code_newDiscount,
"percentage": percentage_newDiscount,
"startDate": sdate_newDiscount,
"endDate": edate_newDiscount
}),function(data){
var text = "your discount code is "+data.code;
swal({title:"Discount Added!", text:text, type:"success"},function(){
window.location='./discountlist.php';
});
});
}else{
swal({title:"Cancelled",text:"", type:"error"},function(){
window.location='./discountlist.php';
});
}
});

Answer

Here is what you can try, if you don't want to show any button and also you can add timeout, so that it will be closed after sometime.

swal({   
    title: "Are you sure?",   
    text: "You want to add this discount?",   
    type: "warning",   
    showCancelButton: true,   
    confirmButtonColor: "#DD6B55", 
    confirmButtonText: "Continue",   
    cancelButtonText: "Cancel",   
    closeOnConfirm: false,   
    closeOnCancel: false 
}, function(isConfirm){   
    if (isConfirm) {
        document.getElementById('message_error_new_discount').innerHTML = '';
        $.post('./CURL/addNewDiscount.php',JSON.stringify({
            "code": discount_code_newDiscount,
            "percentage": percentage_newDiscount,
            "startDate": sdate_newDiscount,
            "endDate": edate_newDiscount
            }),function(data){
                var text = "your discount code is "+data.code;
                swal({title:"Discount Added!",
                      text:text, 
                      type:"success",
                      showCancelButton: false,//There won't be any cancle button
                      showConfirmButton  : false //There won't be any confirm button
                     },function(){
                    window.location='./discountlist.php';
                });
        });
    }else{
        swal({title:"Cancelled",text:"", type:"error"},function(){
            window.location='./discountlist.php';
        });
    }
});
Comments