我有多个chekckbox,它们是从名称为array[]
的数据库中获取的。如何为具有相同名称的多个复选框设置空检查?这是一些不起作用的输入示例,但通常应该起作用。
通常应使用
'array[]': {
validators: {
notEmpty: {
message: 'The array is required'
},
choice: {
min: 1,
max: 20,
message: 'Please choose 1 - 20 topics'
}
}
}
$(document).ready(function() {
$('#formz').bootstrapValidator({
message: 'This value is not valid',
//live: 'submitted',
feedbackIcons: {
valid: 'glyphicon',
invalid: 'glyphicon',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
'firstinput': {
validators: {
notEmpty: {
message: 'Choose from select'
}
}
},
'secondinput': {
validators: {
notEmpty: {
message: 'type any text'
}
}
},
'array[]': {
validators: {
notEmpty: {
message: 'The array is required'
},
choice: {
min: 1,
max: 20,
message: 'Please choose 1 - 20 topics'
}
}
},
},
onSuccess: function(e, data) {
$(document).ready(function() {
$('#spins').show();
});
}
})
.on('error.form.bv', function(e) {
console.log('error.form.bv');
var $form = $(e.target);
console.log($form.data('bootstrapValidator').getInvalidFields());
data.bv.disableSubmitButtons(false);
})
.on('error.field.bv', function(e, data) {
console.log('error.field.bv -->', data);
data.bv.disableSubmitButtons(false);
});
});
<form method='post' action='' enctype="multipart/form-data" name='formz' id='formz'>
<select name='firstinput'>
<option value=''> first </option>
<option value='1'> second </option>
<option value='2'> third </option>
</select>
<input type="text" name="secondinput" />
<input type="checkbox" name="array[]" />
<input type="checkbox" name="array[]" />
<input type="checkbox" name="array[]" />
<input type="checkbox" name="array[]" />
<input type="checkbox" name="array[]" />
<input type="checkbox" name="array[]" />
<input type="checkbox" name="array[]" />
<input type="checkbox" name="array[]" />
<button type="submit" class="btn btn-success btn-block">Apply</button>
</form>
答案 0 :(得分:0)
我发现了错误。所有复选框均应位于<div class="form-group">
内,否则不适用于bootstrapvalidator