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.

6
  • 1
    use remote option to use server to validate a field... see docs Commented Jan 24, 2013 at 12:07
  • I agree with @charlietfl. However check this post stackoverflow.com/questions/1578007/… you can add a custom handler here. Commented Jan 24, 2013 at 12:10
  • @charlietfl: I don't want to do useless request to the server to check for a client validation. Commented Jan 24, 2013 at 12:16
  • @gustavodidomenico: I tried the solution posted there, but it still shows the error messages when I validate. Commented Jan 24, 2013 at 12:16
  • how is it useless? Sending to server saves user a step and a page refresh if field invalid. As for errorPlacement you must not be checking element properly for error not to display. SHow code Commented Jan 24, 2013 at 12:21

1 Answer 1

8

Overriding errorPlacement just returning true will mean all errors are not displayed. You can use the check method on the validator object to quietly check a field. It takes a DOM element as the only argument, so with your code example you would have

$('#myForm').validate().check($('#myInput1')[0])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.