I\'m trying to get bootstrap datepicker to highlight the date selected on the dropdown date picker. It\'s not currently doing this.. What am I missing?
<linkrel="stylesheet"href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="http://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="js/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="js/bootstrap-datepicker.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$('#datePicker')
.datepicker({
format: 'mm/dd/yyyy'
})
.on('changeDate', function(e) {
// Revalidate the date field
$('#eventForm').formValidation('revalidateField', 'date');
});
$('#eventForm').formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
name: {
validators: {
notEmpty: {
message: 'The name is required'
}
}
},
date: {
validators: {
notEmpty: {
message: 'The date is required'
},
date: {
format: 'MM/DD/YYYY',
message: 'The date is not a valid'
}
}
}
}
});
});
</script>
<div class="form-group">
<div class="date">
<div class="input-group input-append date" id="datePicker">
<input type="text" class="form-control" name="date" />
<span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
for this u have to had bootstrap-datepicker.js & bootstrap-datepicker.min.js files.U can also call $('#datePicker').datepicker(); method but it comes with its own default settings. So in the script tag I have applied my own customization in the datepicker() method. Then I just make an datepicker input component in the div tag which is defined in the body tag but I have meke it briefly.
The solution of u r question is the span tags. Which r applying icons on the datepicker input component. I have choosen an calender icon which is glyphicon glyphicon-calendar. But before it have to tell the browser that I am going embedd an icon by writing class="input-group-addon add-on" in the span tag which is used to group icon with the text input.
You have to call the datepicker via javascript $('#datepicker').datepicker();
.
To hightlight the date selected, just include datepicker.css
Code Example / Result
bootstrap.css