t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.4k stars 2.84k forks source link

Action Duplicated - Is there any way to disable button after the first click? #954

Open thiagossnet opened 3 years ago

thiagossnet commented 3 years ago

When I click that button repeatedly, it performs the same action repeatedly. Does anyone know a way to disable the confirmation button after the first click?

My code is:

$('#btn-execute-procedure').on('click', function(e) {
    e.preventDefault();
    swal({
        title: "Are you sure?",
        text: "Confirm this",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Confirm!",
        cancelButtonText: "Cancel!",
        closeOnConfirm: false,
        closeOnCancel: true
    }, function(isConfirm){
        if (isConfirm) {
            $('#execute-form').submit();
        }
    });
abcprintf commented 3 months ago

try : $(".confirm").attr('disabled', 'disabled');

swal({   
       title: "Are you sure?",
        text: "Confirm this",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Confirm!",
        cancelButtonText: "Cancel!",
        closeOnConfirm: false,
        closeOnCancel: true
  }, function(){ 
    $(".confirm").attr('disabled', 'disabled'); 

     if (isConfirm) {
        $('#execute-form').submit();
      }
});