Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery datepicker display year month only

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.

like image 731
Fabio Avatar asked Feb 25 '23 08:02

Fabio


1 Answers

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" />
like image 121
Leniel Maccaferri Avatar answered Feb 27 '23 20:02

Leniel Maccaferri