Search code examples
jquerymaterialize

Reset materialize datepicker using jquery


I have a checkbox and a materialize css datepicker with min and max values.

  $('.CLASS').pickadate({
                    min: new Date(minDate),
                    selectMonths: true, 
                    selectYears: 15, 
                    max: new Date(maxDate)
                });

On check/ uncheck of the checkbox, I want to reset the min and max value. The jquery generates new min and max depending on the checkbox condition. But it doesnt reflect in the final datepicker on UI.

Tried : Creating 2 diff class for check and uncheck scenario and .addClass() and .removeClass()


Solution

  • redraw your picker with the new values:

    var $input = $('.CLASS').pickadate();
    var picker = $input.pickadate('picker');
    picker.stop();
    picker.set({
      min: value,
      max: value
    });
    picker.start();