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 vi
We are using higher version than 2 for Sweat alert and in our case we needed.
for Chrome:
closeOnClickOutside: false
for Firefox:
allowOutsideClick: false
If you are using Sweet Alert 2, you can use this configuration
allowOutsideClick: false
This should work.
It is allowOutsideClick: false for example
swal({
title: "View Cart",
text: "Are you sure?",
type: "warning",
showCancelButton : true,
confirmButtonColor : "#ff0000",
confirmButtonText : "Yes",
allowOutsideClick: false,
CancelButtonText : "No"
},
function() //confirm
{
//if Yes do this
}
);
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,
Swal.fire({
title: 'Do not dismiss!',
icon: 'warning',
showConfirmButton: false,
allowOutsideClick: false,
allowEscapeKey: false
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
The property you are looking for is closeOnClickOutside:
closeOnClickOutside: false
I had the same problem and here's how I solved it: setCanceledOnTouchOutside(false)
var dialog = SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE);
dialog.setTitleText(getString(R.string.session_expired));
dialog.setConfirmClickListener { sDialog ->
sDialog.dismissWithAnimation()
Utils.signOut(context!!)
Handler().postDelayed({
startActivity(getLoginIntent(context!!))
AcTrans.Builder(context!!).performFade()
}, 500)};
dialog.setCanceledOnTouchOutside(false);
dialog.show();