简体   繁体   English

将jquery.validate与jquery.uploadfile一起使用时,验证程序未定义

[英]validator is undefined when using jquery.validate with jquery.uploadfile

I'm trying to use both jquery.validate and jquery.uploadfile in the same page which give me this error : 我试图在同一页面中同时使用jquery.validate和jquery.uploadfile,这给了我这个错误:

TypeError: validator is undefined


if ( validator.settings.rules ) {

and If I don't include jquery.uploadfile there is no problem.How should I use both in the same page? 如果我不包括jquery.uploadfile,那就没有问题。如何在同一页面中同时使用两者?

Thanks 谢谢

I think your problem is you need to specify what element you're looking at. 我认为您的问题是您需要指定要查看的元素。 See link http://jqueryvalidation.org/validate/ 请参阅链接http://jqueryvalidation.org/validate/

It could also be as simple as you are just missing the "$" so $.validator because you are including that new script, the existing may be getting overwritten. 这也可能很简单,因为您只是缺少$ .validator这样的$ .validator,因为您包括了该新脚本,现有脚本可能会被覆盖。

Example: 例:

 $(".selector").validate({
    submitHandler: function(form) {
     // do other things for a valid form
     form.submit();
    }
 });

Another Example: https://elnibs.wordpress.com/2013/10/22/jquery-validation-issue-cannot-read-property-settings-of-undefined/ 另一个示例: https : //elnibs.wordpress.com/2013/10/22/jquery-validation-issue-cannot-read-property-settings-of-undefined/

 var validator = $.data(this[0], 'validator');
    if ( validator ) {
        return validator;
    }

    // Add novalidate tag if HTML5.
    this.attr('novalidate', 'novalidate');

   //HERE it is creating a new one using the constructor   
    validator = new $.validator( options, this[0] );
    $.data(this[0], 'validator', validator);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM