2

In my asp mvc application I use standard client side validation (DataAnnotations + MicrosoftAjax.js + MicrosoftMvcValidation.js). I need to show some popup message (jGrowl) after successful/unsuccessful client side validation (so I can't use ModelState.IsValid). So I search for some standard flag which indicates client side validation status. Does anybody know about it? Does it exist?

Igor V Savchenko
  • 1,076
  • 1
  • 17
  • 32

4 Answers4

7

I don't know if MicrosoftMvcValidation exposes such function but using jQuery you might check if any of the form fields contain errors:

var isValid = $('#formId .input-validation-error').length > 0;
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

If you are using the jquery validate unobtrusive, you should use that:

$(function () {
    $('#formid').submit(function () {
        if (!$(this).valid()) {
            $('#validation-summary').show();
        }
    });
});

From: How to fire jQuery function only if form is valid - Darin Dimitrov

Community
  • 1
  • 1
Ygor Thomaz
  • 507
  • 5
  • 14
0
var pageValid = Page_ClientValidate();

This is a built in function by .NET, just run it and you will know if all validators did pass. You can use it as well inside a Form Check function onClientClick (return func()). and add more of your JS manipulation.

0
            // Now get the validation context and call the validate() method
            var myForm = $("#MainForm");
            var formContext = myForm[0]['__MVC_FormValidation'];
            var errors;
            if (formContext) {
                // validate the form
                errors = formContext.validate("submit");
            }
            if (!formContext || errors.length == 0) {
                // no errors so submit to server
                ...
            } else {
               // found errors
               ...
            }