Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Validation Plugin - can you enable "eager" validation from the options?

I'm using the Jquery Validation plugin on a project.

By default, the plugin validates input when the submit button is clicked. The behavior is "lazy" in order to be unobtrusive to the user. If an error is found, the validation then becomes "eager" and validates input as the user corrects the offending entries.

Is there any way to override the initial "lazy" behavior through an option? I can't find any solution in the documentation.

Example:

If you look at this demo, you will notice that the user can navigate through the form leaving empty text boxes that will fail validation when the user clicks on submit. If the user initially enters an invalid email address on the email textbox, it is not highlighted until the submit button is clicked. After that, the input is validated on each key press and blur event. That is what I'd like to activate from the start.

I understand the design choice of the plugin creator, but I need different behavior.

like image 616
Robert Dean Avatar asked Jun 01 '09 12:06

Robert Dean


People also ask

How we can use jQuery validation plugins in MVC?

UnobtrusiveJavaScriptEnabled" property value back to false and create a new file in "Scripts" folder and name it "script-custom-validator. js". Add the Jquery validator code in it as shown below i.e. The above piece of code attaches my account register form with jQuery form validator by using form ID.

What jQuery Unobstructive validation is?

An unobtrusive validation in jQuery is a set of ASP.Net MVC HTML helper extensions.By using jQuery Validation data attributes along with HTML 5 data attributes, you can perform validation to the client-side.

What does jQuery validation do?

Form validation is a process of confirming the relevant information entered by the user in the input field. Here we will be validating a simple form that consists of a username, password and a confirmed password using jQuery.


2 Answers

Thanks to chaos for guidance on this question:

To enable eager validation on the jquery validation plugin, add the following option to the validate function:

 $('#myform').validate({
    onfocusout: function(element) {
        $(element).valid();
    }
});
like image 165
Robert Dean Avatar answered Nov 09 '22 18:11

Robert Dean


Actually, the default behavior I get is validation on the focusout and keyup events, which I see in the plugin code as defaults. I have to disable those in the plugin configuration in order to only get validation at submit. Perhaps you should post some of your code... I don't think the situation is completely clear.

like image 28
chaos Avatar answered Nov 09 '22 18:11

chaos