我正在使用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);
}
});
有谁知道发生了什么?当我删除'隐藏'属性它可以工作,但我需要它,以便在所有字段都不存在时允许验证。
提前致谢!
答案 0 :(得分:0)
如果您未显示control,则无法重置,因此 您需要启用/禁用验证来解决此难题。
首先将您的输入隐藏起来。 在验证设置中将排除在外:':disabled',就好像您验证了隐藏字段...
if (condition)
{
$("#mytextbox").css("display", "block");
$('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', true);
} else
{
$("#mytextbox").css("display", "none");
$('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', false);
}