Skip to content

Instantly share code, notes, and snippets.

@karki-dennis
Created May 5, 2016 02:58
Show Gist options
  • Save karki-dennis/32cbb320a0618e007a9f0e63e7ec796d to your computer and use it in GitHub Desktop.
Save karki-dennis/32cbb320a0618e007a9f0e63e7ec796d to your computer and use it in GitHub Desktop.
Ui date picker month and year only
<input type="text" class="only-month-year">
<script type="text/javascript">
jQuery(function ($) {
jQuery(document).ready(function ($) {
$(".only-month-year .datepicker").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)));
}
});
$(".only-month-year .datepicker").focus(function () {
$(".ui-datepicker-calendar").hide();
$("#ui-datepicker-div").position({
my: "center top",
at: "center bottom",
of: $(this)
});
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment