I am trying to implement a couple of jQuery date pickers on the same page with the difference that one of them is going to be a month picker using the suggested solution at jQuery UI DatePicker to show month year only (or... http://jsfiddle.net/DBpJe/7722/)
The point is that if I add the following CSS code to my CSS file that hides the ability to select the day... then the two calendars hide the ability to pick days and not just the one that I need... seems like it is an All or Nothing approach
.ui-datepicker-calendar {
display: none;
}
Is there a way I can distinguish from a normal date picker and from the custom month picker that I created (based on jQuery date picker)?
This is my HTML..
<input type="text" size="12" name="codeFlowDate" id="MyDate" class="text" />
<input type="text" size="12" name="codeFlowDate" id="MyMonth" class="text" />
And this is the JS
$(function() {
$('#MyDate').datepicker({
showOn: "button",
buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
buttonImageOnly: true,
//showButtonPanel: true,
maxDate: +0,
});
});
$(function() {
$('#MyMonth').datepicker({
showOn: "button",
buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
buttonImageOnly: true,
maxDate: +0,
dateFormat: "mm/yy",
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
function isDonePressed() {
return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1);
}
if (isDonePressed()) {
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)).trigger('change');
$('.date-picker').focusout() //Added to remove focus from datepicker input box on selecting date
}
},
beforeShow: function(input, inst) {
inst.dpDiv.addClass('month_year_datepicker')
if ((datestr = $(this).val()).length > 0) {
year = datestr.substring(datestr.length - 4, datestr.length);
month = datestr.substring(0, 2);
$(this).datepicker('option', 'defaultDate', new Date(year, month - 1, 1));
$(this).datepicker('setDate', new Date(year, month - 1, 1));
$(".ui-datepicker-calendar").hide();
}
}
})
});
Thanks!
EDIT After seeing the replies...
I've added something like this to my code but nothing happens at all...
$(function() {
$('#MyMonth').datepicker({
showOn: "button",
buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
buttonImageOnly: true,
maxDate: +0,
dateFormat: "mm/yy",
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
function isDonePressed() {
return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1);
}
if (isDonePressed()) {
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)).trigger('change');
$('.date-picker').focusout() //Added to remove focus from datepicker input box on selecting date
}
},
beforeShow: function(input, inst) {
$('.ui-datepicker-calendar').removeClass();
}
})
I noticed that the .ui-datepicker-calendar is defined like this in the HTML..
table class=ui-datepicker-calendar