Eduardo Martin
Eduardo Martin

Reputation: 9

How to disable week days in jquery datepicker? (Enable only weekends and two specific festive days)

I´m getting mad trying this... How to disable week days in jquery datepicker? (Enable only weekends and two specific festive days)

I tryed a lot o codes showed here and away but doesn´t work for me...

And how to disable year dropdown? Want only this current year

Can anybody help me?? Thanks in advance!

Upvotes: 0

Views: 4330

Answers (1)

erikrunia
erikrunia

Reputation: 2383

Here is how to disable weekdays leaving only weekends AND add custom days (your two specific festive days). I don't know what your festive days are so I simply used 1/15/2014 and 1/16/2014 in the example below.

Working Fiddle

var availableDates = ["15-1-2014","16-1-2014"];

$(function()
{
    $('#txtDate').datepicker({ beforeShowDay:
      function(dt)
      { 
        return [dt.getDay() == 0 || dt.getDay() == 6 || available(dt), "" ];
      }
   , changeMonth: true, changeYear: false});
});



function available(date) {
  dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
  if ($.inArray(dmy, availableDates) != -1) {
    return true;
  } else {
    return false;
  }
}

Update: i removed the year dropdown as well now

Update 2: So the reason all your previous attempts were not working is that you have a script you're including (bottom of your html file) that is applying the datepicker initialization code to every element that has class="datepicker"

This is overriding anything you try at the top of your file. Remove the following line from your html file:

<script type='text/javascript' src='http://entrestaciones.es/wp-content/plugins/gravityforms/js/datepicker.js?ver=1.8.1'></script>

or remove the `class="datepicker" from the input elements you dont want auto initialized

Upvotes: 1

Related Questions