jQuery Validate not triggering

前端 未结 1 379
轻奢々
轻奢々 2021-01-25 20:58

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

相关标签:
1条回答
  • 2021-01-25 21:06
    <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/

    0 讨论(0)
提交回复
热议问题