2016-07-19 9 views
0
$(document.getElementById("buttonClicked")).click(function(e) { 
    swal({ 
     imageUrl: "http://www.petdrugsonline.co.uk/images/page-headers/cats-master-header", 
     title: "sentence: ", 
     text: "0/140", 
     type: "input", 
     showCancelButton: true, 
     closeOnConfirm: true, 
     closeOnCancel: true, 
    }, function(text) { 

     if (inputValue.length > 140) { 
      swal.showInputError("You need to write something!"); 
     } 
     // fire post 
     $.post("/index.php", { 
      img: finalDataURL, 
      text: text 
     }).done(function(data) { 

     }); 

     }); 
    }); 

入力(0/140 - > 1/140 - > 2/140 - > etc)内に入力された文字ごとにテキストが更新されるように修正したい場合、ユーザーがsubmitをクリックしようとしたときに、入力した文字数が140を超えると、エラーがポップアップします。sweetalertで文字数制限を設定するにはどうすればよいですか?

今、私のコードはそれをしていません。

答えて

1

現在、SweetAlertには文字カウンタが組み込まれていないため、必要なものを得るためにソースコードを微調整する必要があります。エラーのために

は、あなただけのいくつかと、いくつかのロジックを逃し、正しい軌道に乗っていた:

... 
function(text) { 

    // check the length of "text" instead of "inputValue" 
    // since that's what you're passing into the function 

    if (text.length > 140) { 
     swal.showInputError("You have exceeded 140 characters!"); 
     return false; 
    } else { 
     // Only try submitting once character count validation has passed 
     $.post("/index.php", { 
      img: finalDataURL, 
      text: text 
     }).done(function(data) { 

     }); 
    } 
}); 
関連する問題