No Validation using jQuery Validation Plugin v1.13.1

元气小坏坏 提交于 2019-12-24 11:22:25

问题


This is the error I get: Uncaught TypeError: Cannot read property 'element' of undefined

I'm missing something here that must be right under my nose. I can't get the validation to work within the dialog. I have tried all the things I have found while searching for a solution but I can't figure out what I have done wrong. I have a jsfiddle https://jsfiddle.net/g6rnbtbj/21/ code example. If I un-comment the code line below the jQuery will not even display the dialog.

$('#business-partner-detail').validate();

Someone please point out what I have done wrong. I'm pulling my hair out and I can't afford to lose any more.

Thanks a lot for any insights.


回答1:


"Someone please point out what I have done wrong."

  1. Your JavaScript console error(s) is/are being caused by $('#activity-event-dialog').valid(). You cannot attach the .valid() method to a <div>. You can only attach the .valid() method to an <input>, <textarea>, <select> or <form> element. In your case, you want to test the <form> itself so you need to use $('#business-partner-detail').valid(). You also cannot call .valid() without first calling .validate() to do the initialization.

  2. You cannot comment out the .validate() method as it's required for initializing the plugin on your form. Without it, jQuery Validate will do nothing.

  3. You have not declared any validation rules so the plugin will still do nothing. As a test, I've placed the required="required" attribute within your <textarea> element in the demo below. Otherwise, you can declare rules using the rules option within the .validate() method.

  4. Your jsFiddle includes two instances of jQuery... version 1.11.0 in the "Frameworks & Extensions" section and version 1.11.2 in the "External Resources" section. Remove one of these.

Working DEMO: https://jsfiddle.net/g6rnbtbj/25/



来源:https://stackoverflow.com/questions/29185286/no-validation-using-jquery-validation-plugin-v1-13-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!