0

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 ?

1 Answer 1

3

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

$('#myForm').validate({
    onfocusout: false,
    onkeyup: false,
    ...
});
Sign up to request clarification or add additional context in comments.

1 Comment

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 ?

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.