views:

116

answers:

1

I got the following JQuery validation script :

<script type="text/javascript">
$(document).ready(function() {
    $("#myForm").validate({
        rules: {
            "Content": {
                required: true,
                rangelength: [20, 1000],
                remote: {
                    url: "/RemoteValidation/IsValidContent",
                    timeout: 2000,
                    type: "post"
                }
            }
        },
        messages: {
            "Content": {
                required: "* ...A",
                rangelength: "* ...B",
                remote: "* ...C"
            }
        }
    });
});

And the following controller :

public class RemoteValidationController : Controller
    {
        [HttpPost]
        public virtual JsonResult IsValidContent(MyObject object)
        {    
            return new JsonResult
            {
                Data = true
            };
        }
}

It's only for test purpose, its always return true.

The problem I got is the following. I see the error message (...C) that appears for 1 second and that disapear...

I don't know how to solve that...

Why it appears... it's should never appear...

UPDATE

The problem only appear if I write really quickly in the textarea. If I write slowly, it's doesn't appear. My guess is that between my typing, the validation haven't no time to validated, and by default, it's show the error ?

Anyway, I can change this behavior ?

+2  A: 

You could disable validation when typing but only before submitting the form:

$('#myForm').validate({
    onfocusout: false,
    onkeyup: false,
    ...
});
Darin Dimitrov
That's work and it's a good workaround but it's disabled inline validation. I will do it like that if I can't find anything else. Do you know why the behavior I describe in my post happen ?
Melursus