Prevent SweetAlert to be closed on clicking outside the popup window

前端 未结 13 759
不知归路
不知归路 2021-02-01 04:40

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

相关标签:
13条回答
  • 2021-02-01 04:57

    We are using higher version than 2 for Sweat alert and in our case we needed.

    for Chrome:

    closeOnClickOutside: false
    

    for Firefox:

    allowOutsideClick: false 
    
    0 讨论(0)
  • 2021-02-01 04:59

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

    allowOutsideClick: false
    

    This should work.

    0 讨论(0)
  • 2021-02-01 05:01

    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
                }
    );
    
    0 讨论(0)
  • 2021-02-01 05:02

    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>

    0 讨论(0)
  • 2021-02-01 05:05

    The property you are looking for is closeOnClickOutside:

    closeOnClickOutside: false
    
    0 讨论(0)
  • 2021-02-01 05:08

    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();
    
    0 讨论(0)
提交回复
热议问题