如何排除特定表单字段的验证?
我试图使用'组'设置以区分不需要验证的字段:
<div class="col-md-4">
<input type="text" class="form-control" name="name_1">
</div>
<div class="group">
<div class="col-md-4" group>
<input type="text" class="form-control" name="name_2" data-bv-group=".group">
</div>
</div>
JS:
$('#form').bootstrapValidator({
message: 'This value is not valid',
excluded: [':disabled', ':hidden', ':not(:visible)', '.group'],
group: '.form-group', // Set for all fields
fields: {
name_1: {
validators: {
notEmpty: {
message: required_line_text
}
}
},
name_2: {
field: '.group',
excluded: true
}
}
在表单提交时,name_2字段显示为红色。我希望即使没有内容也能显示绿色。
答案 0 :(得分:1)
HTML:
<div class="col-md-4">
<input type="text" class="form-control" name="name_1">
</div>
<div class="group">
<div class="col-md-4" group>
<input type="text" class="form-control" name="name_2" data-bv-excluded="false">
</div>
</div>
JS:
$('#form').bootstrapValidator({
message: 'This value is not valid',
excluded: [':disabled', ':hidden', ':not(:visible)'],
fields: {
name_1: {
validators: {
notEmpty: {
message: required_line_text
}
}
},
name_2: {
excluded: 'false',
validators: {
...
}
}
}