我通常是 Bootstrap Validator 和 Jquery 的新手,并且正在尝试完成一些事情。
我有一个带有字段的表格,例如
<div class="form-group" id="price_container">
<label for="price">Asking Price</label><input class="form-control" style="width: 50%;" type="text" id="price" name="price" >
</div>
<div class="form-group">
<label for="title">Title</label>
<input class= "form-control" type="text" name="title">
</div>
我可以通过以下方式验证它:
$('#multiform')
.find('[name="list_type"]')
.change(function(e) {
$('#multiform').bootstrapValidator('revalidateField', 'price');
})
.end()
.bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
required: 'fa fa-asterisk',
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
price: {
validators: {
notEmpty: {
message: 'The price is required and cannot be empty'
},
integer: {
message: 'You can only enter an integer'
},
regexp: {
regexp: /^[0-9]+$/,
message: 'The price can only consist of numbers'
}
}
}
}
});
但是,当某个动作发生时,我想禁用验证(我可以将图像上传到服务器)。我在这里查看了文档:http: //bootstrapvalidator.com/examples/enable-validator/
并得到了这个:
$(document).on("click", ".btn-danger", function () {
$('#multiform').bootstrapValidator().enableFieldValidators('price', false);
}
但这根本行不通。我知道这应该相对容易,但作为菜鸟我无法解决。
任何人都可以帮忙吗?
谢谢