Jquery validate throwing error when adding a rule

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

When my js page loads and I create a rule seen below I get a error thrown from the jquery.validate.js library line #138, that says "cannot read property 'settings' of undefined"

settings = $.data( element.form, "validator" ).settings; 

Here is the rule I'm adding and the form I'm adding it too

$('#zipCodeText').rules("add", {   required: true,   minlength: 5,   maxlength: 5,   messages: {     required: "Required input",     minlength: jQuery.validator.format("Please, {0} characters are necessary"),     maxlength: jQuery.validator.format("Please, {0} characters are necessary")   } }); 
@using (Html.BeginForm("SaveLocation", "Manage", FormMethod.Post, new { @class = "form-horizontal", @id = "registerForm", role = "form" })) { 

@Html.EnumDropDownListFor(m => m.Countries, null, new { @id = "countryList", @class = "selectpicker btn-group-lg" })
}

回答1:

JavaScript runtime error: Unable to get property 'settings' of undefined or null reference"

You must first initialize the plugin by calling the .validate() method on your form element.

$('#yourform').validate({ // 


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