JQuery datapicker display year month only

I use datepicker to select only year-month. I filter out part of the day like this:

$(el).datepicker( {changeMonth: true, changeYear: true, dateFormat:'yymm' } ); 

The code comes from the dataInit option in jqGrid. When the user clicks in one day, only the year-month is returned to the input field.

Is there a way to show months that include days?

Thanks.

+4
source share
3 answers

This code works 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" /> 
+8
source

Well, if you are not tied to the datepicker plugin, you can use one of the available β€œperiods”, like this one: http://plugins.jquery.com/project/monthpicker .

(Edit) There is also a previous discussion here: Looking for JavaScript Month Picker .

0
source

jQuery api tweaks tend to break on new releases. They no longer work for me, so I wrote a jQuery widget for this. Please check this: http://lucianocosta.info/jquery.mtz.monthpicker

0
source

Source: https://habr.com/ru/post/1335998/


All Articles