Robert Ross Robert Ross - 12 days ago 5
jQuery Question

min and max date on Datepicker won't work on my project

I have an input field that isusing datepicker. I am trying to set it so the calendar shows as active only weekdays. past dates and dates 1 month ahead of the current date are aimed to be shown as inactive.

Currently, only the weekends are shown as inactive. The past dates are still shown as active.
Can someone please help me fix this?

<input id="date" type="text " class="form-control datepicker" name="date" value="Click to select a date">



$(function() {
$(".datepicker").datepicker({
maxDate: '+1m', //+1m is 1 month from now
minDate: '0', //allow only from now on
daysOfWeekDisabled: [0, 6],
orientation: 'auto'
});

Answer

I think you are using a plugin or something, which you don't need if this is all you are doing. Try using the beforeShowDay parameter with noWeekends like:

      $(".datepicker").datepicker({
        maxDate: '+1m', //+1m is 1 month from now
        minDate: '0', //allow only from now on
        orientation: 'auto',
        beforeShowDay: $.datepicker.noWeekends
      });

Above is jQuery's date picker. This is Bootstrap, so try using startDate/endDate something like:

        $(".datepicker").datepicker({
            endDate: '+1m', //+1m is 1 month from now
            startDate: '0', //allow only from now on
            daysOfWeekDisabled: [0, 6],
            orientation: 'auto'
        });
Comments