I have the following html and js, but it is not triggering the jquery.validate validation on text input field blur or form submit. If I add \"required\" attribute directly to th
<script type="text/javascript" src="jquery.validate.unobtrusive.min.js"></script>
Why are you including the unobtrusive
plugin?
You cannot simultaneously use the unobstrusive
plugin while calling the .validate()
method yourself.
Why?
Because the unobtrusive
plugin automatically constructs and calls the .validate()
method based on the HTML attributes.
Since the plugin only uses the first call to .validate()
to initialize validation, it automatically ignores all subsequent calls. So your call to .validate()
is totally ignored.
If i add "required" directly to the text input field, the default error message kicks in instead.
Because of the unobtrusive
plugin, your call to .validate()
is totally ignored by jQuery Validate. That is why it only works when you put the required
attribute within your input
element.
Completely remove the unobtrusive
plugin and it works fine:
http://jsfiddle.net/ocx864nu/