我正在使用BootstrapValidator,我在重置表单时遇到了问题。当我在排除列表中添加“:隐藏”(我有隐藏的字段,当它们没有显示时,我需要跳过验证),表单将不会重置。我已经包括了图片和更多的文本如下:
$('#frmLifecycleAddEdit').bootstrapValidator({
framework: 'bootstrap',
excluded: [':disabled', ':hidden'],
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
txtStepName: {
validators: {
notEmpty: {
message: 'A valid step name is required.'
}
}
},
ddlCMCreateGroup: {
validators: {
notEmpty: {
message: 'CM creation group is required.'
}
}
},
ddlAssignGroup: {
validators: {
notEmpty: {
message: 'Assign group is required.'
}
}
},
ddlExpireGroup: {
validators: {
notEmpty: {
message: 'Expire group is required.'
}
}
},
txtDaysToExpire: {
validators: {
notEmpty: {
message: 'Expire days is required.'
}
}
},
txtStepNumber: {
validators: {
notEmpty: {
message: 'Step number is required.'
}
}
}
}
});
//View/Edit button click
$("#tblLifecycle tbody").on('click', 'button', function () {
var oTable = $('#tblLifecycle').DataTable();
var data = oTable.row($(this).parents("tr")).data();
$('#frmLifecycleAddEdit').bootstrapValidator('resetForm', true);
if ($('#ddlLifecycleName').val() == 'Accident') {
$('#mtAddEditStep').text('Edit Accident Step');
SetupEditAccident(data);
} else {
$('#mtAddEditStep').text('Edit Countermeasure Step');
SetupEditCountermeasure(data);
}
});在单击按钮时,我正在尝试重置表单。
$("#tblLifecycle tbody").on('click', 'button', function () {
var oTable = $('#tblLifecycle').DataTable();
var data = oTable.row($(this).parents("tr")).data();
$('#frmLifecycleAddEdit').bootstrapValidator('resetForm', true);
if ($('#ddlLifecycleName').val() == 'Accident') {
$('#mtAddEditStep').text('Edit Accident Step');
SetupEditAccident(data);
} else {
$('#mtAddEditStep').text('Edit Countermeasure Step');
SetupEditCountermeasure(data);
}
});有人知道发生了什么吗?当我删除‘:隐藏’属性时,它可以工作,但是当所有字段都不存在时,我需要它来允许验证。
提前感谢!
发布于 2019-05-22 13:15:53
如果你没有显示控制,那么你就不能重置,所以你需要启用/禁用验证来解决这个难题。
把你的输入隐藏在第一位。将排除在外:“:禁用”在验证设置中,就好像您验证隐藏字段一样.
if (condition)
{
$("#mytextbox").css("display", "block");
$('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', true);
} else
{
$("#mytextbox").css("display", "none");
$('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', false);
}https://stackoverflow.com/questions/40354367
复制相似问题