How to set the date in Jquery UI month and year inputs?

Asked

Viewed 32 times

0

Good afternoon guys, I created a Jquery UI datepicker for months and years (only) as follows:

  $.datepicker.setDefaults($.datepicker.regional["pt-BR"]);
  $(datePickerId).datepicker({
    changeMonth: true,
    changeYear: true,
    showButtonPanel:true,
    maxDate: "+3m",
    minDate: "-2y",
    onClose: function(dateText, inst) {
      $(this).prop('disabled', true);
      var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
      var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
      let givenDate = new Date(year, month, 1);
      $(this).datepicker('setDate', givenDate);
      getPercentage(givenDate);
    }
  });
  $(datePickerId).datepicker("setDate", "0")

My question is, when the user will select the date the input is something like this: inserir a descrição da imagem aqui

And this image is the perfect example, in which case the user had selected the month of August, but as soon as they clicked on the datepicker again he brought the default date that is set to bring (the current date), when the user selected a new month/year as I could make the code "remember" which one was selected in the onClose method? Thank you very much in advance.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.