2017-11-18 4 views
0

sweetalert2 v7.0.0을 사용하고 있으며 amount 필드가 비어 있으면 오류를 표시하려고합니다.sweetalert2에서 ValidationError를 표시하는 방법

첫 번째 시도에서 금액을 입력하면 문제없이 작동합니다.

첫 번째 시도에서 필드를 비워두면 유효성 검사 오류가 발생합니다. 그 후에 금액을 쓰고 제출 버튼을 클릭하면 유효성 오류가 사라지지 않습니다. 그것은 두 번째 시간을 확인하지 못한다. 다음은 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) 
    }); 

답변

3

유효성 오류를 다시 설정해야합니다. more details

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

나는 그 방법을 놓쳤다. 고맙습니다. 나는 너에게 충분히 감사 할 수 없다. – hijacker83

+0

감사합니다. 내 하루를 저장했습니다. – ManojMeria