BootStrapValidator - 使用排除时表单不重置
BootStrapValidator - form not resetting when using excluded
我正在使用 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);
}
});
有谁知道发生了什么事吗?当我删除 ':hidden' 属性时它起作用了,但我需要它在那里允许在所有字段不存在时进行验证。
提前致谢!
如果你不显示控制,那么你不能重置,所以
你需要enable/disable验证来解决这个难题。
首先隐藏您的输入。
make excluded: ':disabled' 在验证设置中,就像验证隐藏字段一样...
if (condition)
{
$("#mytextbox").css("display", "block");
$('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', true);
} else
{
$("#mytextbox").css("display", "none");
$('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', false);
}
我正在使用 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);
}
});
有谁知道发生了什么事吗?当我删除 ':hidden' 属性时它起作用了,但我需要它在那里允许在所有字段不存在时进行验证。
提前致谢!
如果你不显示控制,那么你不能重置,所以 你需要enable/disable验证来解决这个难题。
首先隐藏您的输入。 make excluded: ':disabled' 在验证设置中,就像验证隐藏字段一样...
if (condition)
{
$("#mytextbox").css("display", "block");
$('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', true);
} else
{
$("#mytextbox").css("display", "none");
$('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', false);
}