I am using datepicker to select year-month only. I filter out the day part like so:
$(el).datepicker(
{changeMonth: true,
changeYear: true,
dateFormat:'yymm' }
);
The code comes from the dataInit option in jqGrid. When the user clicks in a day only the year-month is passed back to the input box.
Is there any way to just show months where the days are?
Thanks.
This code is working flawlessly for me:
$(function()
{
$(".monthPicker").datepicker({
dateFormat: 'MM yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).val($.datepicker.formatDate('MM yy', new Date(year, month, 1)));
}
});
$(".monthPicker").focus(function () {
$(".ui-datepicker-calendar").hide();
$("#ui-datepicker-div").position({
my: "center top",
at: "center bottom",
of: $(this)
});
});
});
<label for="month">Month: </label>
<input type="text" id="month" name="month" class="monthPicker" />
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