I have read I have read Bootstrap with jQuery Validation Plugin and it's helpful, but it's Bootstrap 3, not Bootstrap 4..
I'm using JQuery Validate with Bootstrap 4, but can't seem to get the label and input field to highlight red when it's invalid.
I thought the valid
and invalid
input classes were default in BS, link? Maybe i'm using them incorrectly.
My code is below, here's a fiddle.
HTML
<form id="myform">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<div class="form-group">
<label for="name" class="control-label">Email address</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
JQuery
$(function() {
$("#myform").validate({
rules: {
name: {
required: true,
minlength: 2
}
},
highlight: function(element) {
$(element).closest('.form-group').removeClass('valid').addClass('invalid');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('invalid').addClass('valid');
},
});
})
Any help is appreciated.