我试图将动态字段添加到引导验证器,例如:
var $option = $education_block.find('[name="education[start][]"], [name="education[end][]"]');
// Add new field
$option.each(function (i, e) {
$doctor_modal_form.bootstrapValidator('addField', $(e));
});
$doctor_modal_form.bootstrapValidator({
fields: {
'education[start][]': {
validators: {
date: {
format: 'DD.MM.YYYY',
message: 'Неверная дата начала обучения.'
}
}
},
'education[end][]': {
validators: {
date: {
format: 'DD.MM.YYYY',
message: 'Неверная дата окончания обучения.'
}
}
}
}
})
并在以下字段中输入日期时收到错误:
Uncaught TypeError: Cannot read property 'find' of undefined
at b.isValidContainer (bootstrapValidator.min.js:11)
at b.updateStatus (bootstrapValidator.min.js:11)
at b.validateField (bootstrapValidator.min.js:11)
at HTMLInputElement.<anonymous> (bootstrapValidator.min.js:11)
at HTMLInputElement.dispatch (jquery.min.js:3)
at HTMLInputElement.r.handle (jquery.min.js:3)
isValidContainer @ bootstrapValidator.min.js:11
updateStatus @ bootstrapValidator.min.js:11
validateField @ bootstrapValidator.min.js:11
(anonymous) @ bootstrapValidator.min.js:11
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
g.data("bv.messages").find('.help-block[data-bv-validator][data-bv-for="'+f+'"]')
你能告诉我哪里出了问题吗?什么选项和我必须添加的位置?
<div class="col-sm-4">
<div class="form-group">
<label class="col-sm-2 control-label"><span>Начало</span></label>
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
<input name="education[start][]" type="date" class="form-control"
data-bv-field="education[start][]" value="<%-start%>">
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label class="col-sm-2 control-label"><span>Конец</span></label>
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
<input name="education[end][]" type="date" class="form-control"
data-bv-field="education[end][]" value="<%-end%>">
</div>
</div>
</div>
</div>
it教育块声明用于关闭所有问题。在JS中,我非常讲究。
答案 0 :(得分:0)
我的解决方案:
if ($f.data('bv.messages')) {
if ($f.data('bv.messages') <-- insert line to check
.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]')
.filter('[data-bv-result="' + this.STATUS_INVALID + '"]')
.length > 0) {
return false;
}
}