3

I am using jQuery validation in ASP.NET MVC 3. Is there a possibility to check if an input is valid without showing the error messages next to the actual input?

I have tried:

$("#myForm").validate().element("#myInput1"); // this shows the error message only for the myInput1 element

$('#myForm').valid(); // this shows the error messages for all fields.

I am not trying to suppress the errors showing forever, I just want to check if the fields are valid by using the validation created on server. That one is subject to change so I do not want to have two validation definitions (one on client and one on server). Thanks!

Later Edit:

var a = $('#myForm').validate({
    errorPlacement: function(error,element) {
                       return true;
                    }
}).element("#myInput1");
alert(a);

This also shows the errors.

4

1 に答える 1

8

errorPlacementをオーバーライドしてtrueを返すだけでは、すべてのエラーが表示されないことを意味します。バリデータオブジェクトのcheckメソッドを使用して、フィールドを静かにチェックできます。唯一の引数としてDOM要素を使用するため、コード例では次のようになります。

$('#myForm').validate().check($('#myInput1')[0])
于 2013-01-24T13:45:15.523 に答える