I have several datepickers on the same page and need one to only display the month and year, while others should show complete calendar with days. I know that to hide days from a lone datepicker I can do something like:
<style>
.ui-datepicker-calendar {
display: none;
}
</style>
But that hides the dates from all calendars. How can I make sure the other datepicker keeps the calendar view?
Edit I did try nesting CSS but am still missing something. For HTML part I have roughly:
<div id="monthOnly"><input type="text" class="monthly-picker" name="mdate"></div>
And JS code $('.monthly-picker').datepicker();
Still, doing something like
<style>
#monthOnly .ui-datepicker-calendar {
display: none;
}
</style>
Does not produce desired results.
give the use an id on a container element.
<style>
#monthOnly .ui-datepicker-calendar {
display: none;
}
</style>
EDIT: http://jsfiddle.net/h8DWR/ is a solution to deal with the idiosyncrasies of datepicker. The idea is use a style element to add the style when the specific datepicker is chosen and then remove it when it is closed.
I did a little different ...
HTML
<label for="startDate">Date :</label>
<input name="startDate" id="startDate" class="date-picker" />
CSS
.hide-calendar .ui-datepicker-calendar {
display: none;
}
jQuery
$(function() {
$('.date-picker').datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
yearRange: '1980:' + new Date().getFullYear(),
beforeShow: function(el, dp) {
$('#ui-datepicker-div').addClass('hide-calendar');
},
onClose: function(dateText, inst) {
$('#ui-datepicker-div').removeClass('hide-calendar');
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
});
Fiddle
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