Jquery validation plugin - TypeError: $(…).validate is not a function

后端 未结 8 1076
不知归路
不知归路 2020-12-01 08:45

My script throw errors:

TypeError: jQuery.validator is undefined additional-methods.js:20 TypeError: $(...).validate is not a function index.php:115

相关标签:
8条回答
  • 2020-12-01 09:39

    It looks like the JavaScript error your getting is probably being caused by

    password: {
        required:true,
        rangelenght:[4.20]
    },
    

    As the [4.20] should be [4,20], which i'd guess is throwing off the validation code in additional-methods hence giving the type error's you posted.

    Edit: As others have noted in the below comments rangelenght is also misspelled & jquery.validate.js library appears to be missing (assuming its not compiled in to one of your other assets)

    0 讨论(0)
  • 2020-12-01 09:45

    for me, the problem was from require('jquery-validation') i added in the begging of that js file which Validate method used which is necessary as an npm module

    unfortunately, when web pack compiles the js files, they aren't in order, so that the validate method is before defining it! and the error comes

    so better to use another js file for compiling this library or use local validate method file or even using CDN but in all cases make sure you attached jquery before

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