如何在 sweetalert2 中显示 ValidationError

how to show ValidationError in sweetalert2

我正在使用 sweetalert2 v7.0.0,如果金额字段为空,我会尝试显示错误。

当我第一次尝试输入金额时,它没有问题。

当我第一次尝试将该字段留空时,出现验证错误。之后,当我写下金额并单击提交按钮时,验证错误不会消失。它卡住不会第二次验证。这里是jsfiddle link。如果你能给我指路,我将不胜感激。我哪里做错了?

<a href="#" class="refundbutton"><i class="fa fa-undo"></i> Refund</a>

$(".refundbutton").click(function(){
    swal({
      title: 'Enter Refund Details',
      html:'<label for="ipt" class=" control-label"><span class="oval">1</span> Select refund type</label><select class="form-control refund_type"><option value="4"> Credit Card </option> <option value="5"> Cash </option></select>' +
      '<label for="ipt" class=" control-label"><span class="oval">2</span> Enter refund amount</label><input type="text" class="form-control nDiscount_fixed" autocomplete="off" style="height: 34px;" value="">',
      showCancelButton: true,
      confirmButtonText: 'Submit',
          preConfirm: function (value) {
        return new Promise(function (resolve, reject) {

            if ($(".nDiscount_fixed").val() === "") {
              swal.showValidationError(
                'please enter a refund amount.'
              )
            }
             resolve([ $('.refund_type').val(), $('.nDiscount_fixed').val() ]) 

        })
      }
    }).then(function (result) {
    var swalrebateamount = parseFloat($('.nDiscount_fixed').val()).toFixed(2);

    if (swalrebateamount !="" && swalrebateamount !="0" ) { 
    //some code
    } 
    }).catch(swal.noop)
    });

您必须重置验证错误。 more details

    if ($(".nDiscount_fixed").val() === "") {
              swal.showValidationError(
                'please enter a refund amount.'
              )
    }
    else
    {
           swal.resetValidationError();
    }