Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent SweetAlert to be closed on clicking outside the popup window

I am using Sweet Alert for a popup on my product view in an E-commerce Application with two buttons: one for going on cart View and another for reloading the view.

But when a user clicks outside of the popup, the popup window closes automatically. I've tried following properties to stop it to be closed but nothing works :

hideOnOverlayClick: false,
hideOnContentClick: false,
closeClick: false,
helpers: {
    overlay: { closeClick: false } 
}

Any help/suggestion is highly appreciated.

Thanks.

like image 901
Saqib A. Azhar Avatar asked Dec 11 '17 08:12

Saqib A. Azhar


4 Answers

If you are using Sweet Alert 2, you can use this configuration

allowOutsideClick: false

This should work.

like image 131
Halawa Avatar answered Oct 14 '22 07:10

Halawa


The property you are looking for is closeOnClickOutside:

closeOnClickOutside: false
like image 32
Channel Avatar answered Oct 14 '22 09:10

Channel


For SweetAlert 2:

allowOutsideClick: false

and version 3 and some below version 2:

closeOnClickOutside: false
like image 18
SouravOrii Avatar answered Oct 14 '22 07:10

SouravOrii


Regarding Sweet Alert 2 (More effective solution)

Actually all answers here don't cover another way to dismiss the popup. And that's using keyboard. Especially the ESC key. In order to prevent that you would want to add two options instead of one.

allowOutsideClick: false,
allowEscapeKey: false,

Quick example:

Swal.fire({
  title: 'Do not dismiss!',
  icon: 'warning',
  showConfirmButton: false,
  allowOutsideClick: false,
  allowEscapeKey: false
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
like image 35
Ph0enixKM Avatar answered Oct 14 '22 07:10

Ph0enixKM