views:

105

answers:

1

Is anyone doing dyanamic client validation and if so how are you doing it.

I have a view where client side validation is enabled through jquery validator ( see below)

<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
        <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
        <script src="../../Scripts/MicrosoftMvcJQueryValidation.js" type="text/javascript"></script>
        <% Html.EnableClientValidation(); %>

This results in javascript code been generated on my page which calls validate when I click the submit button:

function __MVC_EnableClientValidation(validationContext) {
    ....
    theForm.validate(options);
}

If I want validation to occur when the onblur event occurs on a textbox how can i get this to work?

A: 

Personally I like the ASP.NET MVC Validation but the jquery one can work too

$(document).ready(function () {
 $("#myform").validate();
 $("a.check").click(function() {
     alert("Valid: " + $("#myform").valid());
 });  
});

or if you want to really hammer it home

    $(document).ready(function () {
        $("input[type='text']").blur(function () {
            $("#myform").validate();
            $("a.check").click(function () {
                alert("Valid: " + $("#myform").valid());
            });  
        });
    });

Those should in theory work ... at any rate once the user clicks submit then onblur starts validating which seems to be enough for the jquery people.

Hurricanepkt