Saturday, June 22, 2013

jQuery UI DatePicker to show month year only

  $("#monthPicker").datepicker({
    dateFormat: 'yy-mm',
    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('yy-mm', new Date(year, month, 1)));
      $(this).datepicker('setDate', new Date(year, month, 1));
    }
  });

  $("#monthPicker").focus(function () {
    $(".ui-datepicker-calendar").hide();
    //$("#ui-datepicker-div").position({
    //  my: "center top",
    //  at: "center bottom",
    //  of: $(this)
    //});
  });

Reference:
http://stackoverflow.com/questions/2208480/jquery-ui-datepicker-to-show-month-year-only
http://thiamteck.blogspot.ca/2011/03/jquery-ui-datepicker-with-month-and.html

No comments: