Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use jQuery Validate directly, without the submit button?

I have done various tests and I have found that the jQuery validate function works only with the submit button.

Am I right? If yes how can I use the jQuery validate plugins without the submit button?

like image 954
learning Avatar asked Feb 26 '10 07:02

learning


2 Answers

You can use the method valid() to invoke the validator directly.

It will return bool indicating whether the form is valid or not.

Here is an example, from jQuery documentation:

$("#myform").validate();
$("a.check").click(function() {
    alert("Valid: " + $("#myform").valid());
    return false;
});
like image 56
Sagi Avatar answered Jan 03 '23 23:01

Sagi


When you call the validate method on the jQuery validate plugin it returns an instance of Validator which you should store. When you need to, you can call the form or showErrors methods on the Validator instance to either validate the form, or validate the form and show the errors respectively.

like image 20
casperOne Avatar answered Jan 04 '23 00:01

casperOne