Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valid vs Validate

I am trying to learn jQuery and have stumbled across a strange problem (perhaps strange only to me). So here goes: I have a form with id mainform in my app. Now I wanted to validate the form with jQuery. Also I wanted to set the invalid fields in blue color. For that I added css

.error{
  background-color:blue;
}

When I run $('form#mainform').valid(); in the console, I get the highlights and everything works fine. However when I run $('form#mainform').validate();, I get lots of data and nothing happens.

Also if I run .valid() before validate(), various options such as error placement etc. don't seem to work.

I want to know the difference between these, why they are behaving so differently and where they should be used. I will appreciate if anyone can point me in right direction.

Note: I am using jquery.validate.js

like image 928
Akash Avatar asked Jul 01 '13 12:07

Akash


People also ask

What is the difference between valid and validate?

The meaning of "valid" is given as "actually supporting the intended point or claim" from which "validate" is "to confirm the truth or value of".

What does valid validate mean?

confirm, corroborate, substantiate, verify, authenticate, validate mean to attest to the truth or validity of something.

What are examples of validate?

To validate is to confirm, legalize, or prove the accuracy of something. Research showing that smoking is dangerous is an example of something that validates claims that smoking is dangerous.

What does @validated do?

The @Validated annotation is a class-level annotation that we can use to tell Spring to validate parameters that are passed into a method of the annotated class.

What makes something validated?

validate Add to list Share. To validate is to prove that something is based on truth or fact, or is acceptable. It can also mean to make something, like a contract, legal. You may need someone to validate your feelings, which means that you want to hear, “No, you're not crazy.

What is a validation document?

Validation Documentation means the collection of all documentation demonstrating that Product equivalence and all applicable regulatory requirements, and any other requirements agreed by the Parties, have been achieved with respect to a proposed new Facility, including master validation plans, qualification ...


2 Answers

There are several differences between valid and validate. Interestingly, although the docs state that

"validate needs to be called on the form before checking it using this method"

this isn't actually the case, as valid calls validate() anyway.

The two major differences are

  1. If you want to pass options into the plugin, you must call validate({...})
  2. validate() doesn't highlight any errors, whereas valid() does. You could say that valid performs 'eager' validation whereas validate sets up a 'lazy' validation, basically if you call validate() you won't see any immediate change on the page, whereas with valid() you might.
  3. valid can be called on a subset of form elements, whereas validate must be called on the form itself:

    $('form').validate({/* options here */});

    $('.myfields').valid()

like image 184
Dr Blowhard Avatar answered Oct 20 '22 23:10

Dr Blowhard


Assuming you are using Jquery validate library.

Docs saying

validate() needs to be called on the form before checking it using valid() method.

Not .valid() before validate()

http://jqueryvalidation.org/valid/

http://jqueryvalidation.org/validate

like image 42
Suresh Atta Avatar answered Oct 20 '22 22:10

Suresh Atta