Customize days that can be clicked on a Calendar popup I am creating a form in Drupal 7 with the form API. Right now, I can create an ordinary calendar input field with the following code:

   $form['services_tab']['schedule_datepicker'] = array(
    '#title' =&gt; t('Pick the desired date'),
    '#type' =&gt; 'date_popup',
    '#date_year_range' =&gt; '0:0',
    '#date_format' =&gt; 'Y-m-d',
    '#prefix' =&gt; '&lt;div id="datepicker-schedule"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  );


Right now I can get the beautiful calendar popup to appear. What I am trying to achieve is enable or disable certain dates based on a rule like: disable all Saturdays and Sundays; or even remove the click state from specific dates based on a list of national holidays...

Is this something that can be achieved with PHP coding, or does it need to be done with jQuery? In case jQuery is the solution, I would appreciate any hints on how to do that... The calendar is a table, but table cells don't have an ID or something that could help me find and disable them based on a rule...

Thank you.
You can pass some Datepicker options from php to the date_popup element through the '#datepicker_options' key:

&lt;?php
$form['date'] = array(
  '#title' =&gt; t('Pick the desired date'),
  '#type' =&gt; 'date_popup',
  '#datepicker_options' =&gt; array(
    'minDate' =&gt; 0,
  ),
);


With this method you can pass almost any option but those that accept a function as value, as beforeShowDay, the one needed to restrict weekends or holidays according to the answer referenced by Nikit: https://stackoverflow.com/questions/501943/can-the-jquery-ui-datepicker-be-made-to-disable-saturdays-and-sundays-and-holid

Hence, javascript is required. First you need to include a custom js file from your module code:

&lt;?php
drupal_add_js(drupal_get_path('module', 'FOO') . '/FOO.js');


and provide some code in FOO.js to extend the settings set by date_popup module with our own options.

Here's an example that add the basic option to disable weekends for all datepicker widgets in the page:

(function ($) {
Drupal.behaviors.FOO = {
  attach: function (context) {
    for (var id in Drupal.settings.datePopup) {
      Drupal.settings.datePopup[id].settings.beforeShowDay = $.datepicker.noWeekends;
    }
  }
};
})(jQuery);


Extend to holidays is left as an exercise to the reader :)

Note: the three occurences of FOO in my examples doesn't need to be the same literal, ie: you can provide a BAZ behaviour in BAR.js from FOO.module.

Update: to extend the above for custom days availability, just add a function returning true/false for the day received by parameters.

(function ($) {
Drupal.behaviors.FOO = {
  attach: function (context) {
    for (var id in Drupal.settings.datePopup) {
      Drupal.settings.datePopup[id].settings.beforeShowDay = checkDate;
    }
  }
};

function checkDate(date) {
  if ((date.getDate() % 2) == 0) {
    return [false, 'Even days not available'];
  }
  else {
    return [true, 'Odd days are fine'];
  }
}
})(jQuery);


You can find a more complete example in Date Restrictions module.