问题
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."
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.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.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.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