I'm new to Bootstrap Validator and Jquery generally and am trying to accomplish something.
I have a form with fields e.g.
<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>
and I have it validating ok with:
$('#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'
}
}
}
}
});
However, when a certain action is taking place, I'd like to disable the valiadation (do i can upload images to the server). I've looked at the documentation here: http://bootstrapvalidator.com/examples/enable-validator/
and have got this:
$(document).on("click", ".btn-danger", function () {
$('#multiform').bootstrapValidator().enableFieldValidators('price', false);
}
but this is simply not working. I know it should be relatively easy, but being a noob I cant work it out.
Can anyone help?
Thanks
Here is a working version:http://jsfiddle.net/silviagreen/ym48cfxd/
$(document).on("click", ".btn-danger", function () {
var bootstrapValidator = $('#multiform').data('bootstrapValidator');
bootstrapValidator.enableFieldValidators('price', false);
});
Have a look at the js fiddle to know which version of jquery, bootstrap and bootstrapValidator I used to make it work.
I know this is an old post but maybe this can be useful to other people.