Conditional Validation With Bootstrapvalidator
I'm using BootstrapValidator plugin to validate a form, however i have following problem. I have a 'Phone' field and a 'Mobile' field if the user does not enter either of them, I w
Solution 1:
This seems to be working for a lot of people derived from this post:
$('form').validate({
rules: {
Phone: {
required: true
},
Mobile: {
required: true
}
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
and the html:
<form><divclass="form-group"><labelclass="control-label"for="Phone">Phone:</label><divclass="input-group"><inputclass="form-control"name="Phone"type="text" /></div></div><divclass="form-group"><labelclass="control-label"for="Mobile">Mobile:</label><divclass="input-group"><inputclass="form-control"name="Mobile"type="text" /></div></div><buttontype="submit"class="btn btn-primary">Submit</button></form>
Post a Comment for "Conditional Validation With Bootstrapvalidator"