How to keep sweetalert2 open when a specific button is pressed?

  javascript, sweetalert2

I have the following sweet-alert-2 in JavaScript where a list of check-boxes are provided. The idea is to provide 3 buttons for this alert message:

  1. Select All (checkboxes options)
  2. Confirm
  3. Cancel

The Confirm and Cancel Button work as expected. Thus, Cancel will close modal, and confirm will perform some javascript and eventually close the modal.

However, I do not want to close the modal when the button Select All is pressed. I simply want to execute the jQuery provided below to check all checkboxes. How to prevent the alert message from closing when a specific button is pressed?

Swal.fire({
    title: '<strong>Select Emergency Contacts to be alerted:</strong>',
    icon: 'info',
    html: checkboxes,
    showDenyButton: true,
    showConfirmButton: true,
    showCancelButton: true, 
    denyButtonText: 'Alert',
    confirmButtonText: 'Select All',
    cancelButtonText: 'Cancel',
}).then((result) => {
    //SELECT ALL OPTIONS:
    if (result.isConfirmed) {
        $("input:checkbox[name=emergency_contacts]").each(function(){
            $(this).prop('checked', true);
        });
        alert("after?") //Executes
        //Closes modal.
        //Swal.fire.keepOpened = true; //Doesn't work


    //ALERT EMERGENCY USERS:
    } else if (result.isDenied) {
        Swal.fire('ALERT', '', 'info')
    //CANCELLED:
    } else{
        //close modal
    }
});

enter image description here

Source: Ask Javascript Questions

LEAVE A COMMENT