jquery validate always returning true
Did you add required to the HTML tag of the <input>
or <textarea>
?
IE:
<input id="cemail" type="email" name="email" required/>
Try
$.validator.unobtrusive.parse($('#parameterForm'))
before calling
$('#parameterForm').valid()
Question already has an accepted answer, but here's another possible reason for anyone that finds this in the future...
Make sure that your first validated element in the form has a name
attribute, like this:
<input type=text required name='blah' />
I spent 2 hours tracking down this same issue, and I found that if the FIRST validated element in the form has a name
attribute then everything works as you would expect (that is, .valid()
will return false if the form is invalid). It seems to make no difference whether the other validated elements have name attributes or not.
In normal forms, you definitely need name attributes because that's what's used when the data gets submitted to the server. But in more modern environments, such as those using Knockout, there's no reason to have a name
attribute on input elements, because the data-binding works to keep your data model updated.