如何解决无法读取未定义的属性“调用”检查元素“UnitName”时发生异常,请检查“minLength”方法
仅当该字段实际有效时,我才会收到此错误。如果该字段为“空白”,则 invalidHandler 会按预期触发,但如果该字段中有任何文本,我会收到上述错误。全文如下:
jquery.validate.js:791 Uncaught TypeError: Cannot read property 'call' of undefined. Exception occurred when checking element UnitName,check the 'minLength' method.
at $.validator.check (jquery.validate.js:791)
at $.validator.element (jquery.validate.js:502)
at $.validator.onfocusout (jquery.validate.js:302)
at HTMLInputElement.delegate (jquery.validate.js:433)
at HTMLFormElement.dispatch (jquery.js:5183)
at HTMLFormElement.elemData.handle (jquery.js:4991)
at Object.trigger (jquery.js:8249)
at Object.simulate (jquery.js:8318)
at HTMLDocument.handler (jquery.js:8352)
无论是否设置 minLength 值,都会出现错误。
这是我的验证码:
validator = $("#SaveAssessmentForm").validate({
rules: {
UnitName: {
required: true,minLength: 3,maxLength: 150
},},invalidHandler: function (event,validator) {
swal.fire({
"title": "","text": "Assessment Name is required!","type": "error","confirmButtonClass": "btn btn-secondary"
});
event.preventDefault();
KTUtil.scrollTop();
},submitHandler: function (form) {
return false;
}
});
});
这是我的提交代码:
function saveAssessment(assessmentId,type) {
var btn = $('#saveAssessment');
var form = $('#SaveAssessmentForm');
if (validator.form()) {
KTApp.block(doc,{ message: 'Please wait while we save the Assessment...' });
form.ajaxSubmit({
data: {
AssessmentId: assessmentId
},type: 'POST',success: function (data) {
KTApp.unblock(doc);
KTApp.unprogress(btn);
swal.fire({
"title": "","text": "The request has been saved!","type": "success","confirmButtonClass": "btn btn-secondary","confirmButtonText": 'Close',}).then(function () {
if (type == 1) {
window.location.href = '@Url.Action("CompetencyConfiguration","Config",new {area = "Competency"})'
}
else {
location.reload();
}
});
},error: function () {
KTApp.unblock(doc);
KTApp.unprogress(btn);
swal.fire({
"title": "","text": "Something went wrong during submission. Please review your form and try again. If the issue persists then please contact Support.","confirmButtonClass": "btn btn-secondary"
});
}
});
}
}
这是我的表格:
@using (Html.BeginForm("SaveAssessment",FormMethod.Post,new { id = "SaveAssessmentForm" }))
{
<div class="row">
<div class="col-md-6">
<label class="kt-popover kt-font-bold" data-toggle="kt-popover" data-placement="top" data-trigger="hover" data-html="true" data-content="The name of the Assessment that will be displayed. (Max-Length:150)">Assessment Name</label>
@Html.TextBoxFor(x => x.AssessmentName,new { @class = "form-control",id = "AssessmentName" })
</div>
<div class="col-md-2">
<label class="kt-popover kt-font-bold" data-toggle="kt-popover" data-placement="top" data-trigger="hover" data-html="true" data-content="The date that the Assessment will become effective and will display for users to take.">Effective Date</label>
<input type="text" class="date form-control" name="EffectiveDate" id="EffectiveDate" value="@(Model.EffectiveDate ?? "")" placeholder="Effective Date" />
</div>
<div class="col-md-2">
<label class="kt-popover" data-toggle="kt-popover" data-placement="top" data-trigger="hover" data-html="true" data-content="The date that the Assessments is set to expire. Useful for turning off Assessments on a certain date. Leave blank to never expire">Expiration Date</label>
<input type="text" class="date form-control" name="ExpirationDate" id="ExpirationDate" value="@(Model.ExpirationDate ?? "")" placeholder="Effective Date" />
</div>
<div class="col-md-2">
<label class="kt-popover" data-toggle="kt-popover" data-placement="top" data-trigger="hover" title="" data-html="true" data-content="Determines whether the Assessment is available.">Active</label>
<div class="" style="">
<span class="kt-switch kt-switch--outline kt-switch--icon kt-switch--success kt-switch--sm">
<label style="vertical-align:middle;">
@Html.CheckBoxFor(x => x.Active,new { Active = true })
<span></span>
</label>
</span>
</div>
</div>
</div>
<div style="padding:20px">
<div class="kt-portlet kt-portlet--bordered">
<div class="kt-portlet__head kt-portlet__head--lg headingTwo">
<div class="kt-portlet__head-label">
<h4 class="kt-portlet__head-title" style="color:white">
Units
</h4>
</div>
<div class="kt-portlet__head-toolbar">
<span style="padding-left:300px">
<label style="color:white;padding-right:10px">Add existing unit:</label>
</span>
<span>
@Html.DropDownList("Unit",new SelectList(Model.unitSelect,"Id","Text"),"Select a Unit",style = "width: 500px" })
</span>
</div>
</div>
<div class="kt-portlet__body" id="UnitEditor">
@if (Model.Units != null)
{
foreach (ICAN.Models.Competency.viewmodels.AssessmentUnitModel unit in Model.Units)
{
Html.RenderPartial("UnitEditorRow",unit);
}
}
</div>
</div>
</div>
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。