jQuery validate stays valid after ajax postback

I have a form that with a validator that works the first time but not the second time. The code validates on the client side without any problem but as soon as the form is submitted and the form is partially render although fields are invalid the $('form').valid() continues returning true always.

The data is validated at the server side but then the error is displayed twice. My rules are set by MVC4 generated code thus rules are correctly initiated.

Not sure if is possible re-validate the form. Please note that $('form').validate() does not work. It returns the validator and valid() returns true all the time.

Here the options. displayErrors function find the html element that shows the errors.

/* Set additional settings for the validator */
        var options = {
            onfocusout: false,
            onkeyup: false,
            onclick: false,
            showErrors: function (errorMap, errorList) {
                displayErrors(errorList, false);
            }
        };

Help is appreciated.

Answers


I solved this by doing something like this

$vlt = $('#myForm').validate(); //-- get validator
$vlt.checkForm(); 

if ( $('#myForm').valid()){
//-- code
}

It seems like doing it in this way the validator was able to picked the new changes. Not sure if I mention that the form was being re-render and replaced by $('#okok').html(newStuff);

Anyway, I could maybe conclude, I won't recommend this plugin to a friend :))


Need Your Help

Java 7 nio list directory with wildcard

java nio

I'd like to find a file in a directory using wildcard. I have this in Java 6 but want to convert the code to Java 7 NIO:

Visual Studio .dll Reference not found?

visual-studio dll reference

I had never had this error before, and I didn't move any file, or exclude any reference.