I'm creating a form in Drupal 7 with the form API. Right now, I try to disable Mondays in the popup calendar. My form:

$form['Fecha']=array(
       	'#title' => t('Fecha'),
		'#type' => 'date_popup', 
		'#date_format' => 'j F Y', 
		'#date_year_range'=> '0:+1', 
		'#datepicker_options' => array('minDate' => 0,'firstDay' => 1,),  
		'#date_label_position' => 'none', 
		'#default_value' => date('Y-m-d'),
				
	);

I include a js file in my module "Reservas" (reservas.module):

function reservas_init() {
$path = drupal_get_path('module', 'reservas');  

// load ui.datepicker from core
drupal_add_library('system', 'ui.datepicker');
// and our js
drupal_add_js($path . '/js/cal_improve.js');
}

and the code in file .js (cal_improve.js):

(function ($) {
    Drupal.behaviors.cal_improve = {
          attach: function (context) {
          for (var id in Drupal.settings.datePopup) {
          Drupal.settings.datePopup[id].settings.beforeShowDay =$('#onlyMondays').datepicker({beforeShowDay:onlyMondays});                  
          }
        }
      }

    onlyMondays: function(date){
          return [(date.getDay() == 1), ""];
    }

})(jQuery);

The calendar popup appear but mondays are enables. Any idea?. Thank you in advance!

Comments

i32orgrr’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jonhattan’s picture

Checkout Work Calendar module http://drupal.org/project/work_calendar. it provides an easy way to do what you want for date fields with no need to code. If you prefer coding, just create a work calendar and add a #work_calendar key to your date_popup form element.

xbrianx’s picture

Anyway to customize the popup so days can't be click-able if a node is not attached to it? I am going to look into that work calender though some more, but I didn't see anything about nodes and availability there.