Is it possible to use the JQuery Validation to validate the Bootstrap Datepicker? As it doesn't expose the input
field, I can't get it to validate.
Example: https://jsfiddle.net/Khrys/2rcr9j5s/
$.validator.setDefaults({
submitHandler: function() {
form.submit()
}
});
$().ready(function() {
var container = $('div.containerx');
$("#Form").validate({
ignore: [],
messages: {
StartTime: {
required: "Select the StartTime."
}
},
errorContainer: container,
errorLabelContainer: $("span", container),
highlight: function ( element, errorClass, validClass ) {
$('#StartTime').addClass( "btn-danger" );
$('#Filter').addClass( "btn-danger" );
},
unhighlight: function ( element, errorClass, validClass ) {
$('#StartTime').removeClass( "btn-danger" );
$('#Filter').removeClass( "btn-danger" );
}
});
});
Update:
Class btn-danger
needs to be applied to the element correctly.
https://jsfiddle.net/2rcr9j5s/4/
Have updated the fiddle: https://jsfiddle.net/2rcr9j5s/1/
$.validator.setDefaults({
submitHandler: function() {
form.submit()
}
});
$().ready(function() {
var container = $('div.containerx');
$("#Form").validate({
ignore: [],
rules:{
StartTime: {
required: true
}
},
messages: {
StartTime: {
required: "Select the StartTime."
}
},
errorContainer: container,
errorLabelContainer: $("span", container),
highlight: function ( element, errorClass, validClass ) {
$('#StartTime').addClass( "btn-danger" );
$('#Filter').addClass( "btn-danger" );
},
unhighlight: function ( element, errorClass, validClass ) {
$('#StartTime').removeClass( "btn-danger" );
$('#Filter').removeClass( "btn-danger" );
}
});
});
Set the datepicker to be required.
Was this what you needed?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With