Mr Bell
Mr Bell

Reputation: 9366

MVC Client Side Validation without preventing form submit

I have a form that allows the user to edit my model. They can save the data, as well as publish it. When the user hits save I want to go ahead and save the form even if its doesnt pass validation so that can come back and finish filling it out later. But if they blur out of a field and its required I still want it to turn red and show the error message. So basically I want normal client side validation without it preventing the form from posting.

Is there a way to do that?

Upvotes: 1

Views: 4249

Answers (1)

Adam Tuliper
Adam Tuliper

Reputation: 30152

simply override the form submit and that should disable the validation.

$(function () {
    $("form").submit(function () {
        if (!$(this).valid()) {
            //form is not valid         
            return true;
        }
    });
});

You dont need the check there obviously and can just return true, thats just to show you how to check if its valid.

Upvotes: 4

Related Questions