I can't figure out how to change the jQuery UI Calendar implemented by the Date module to allow only weekends to be selected. I know what I need to do if I create the calendar myself but I don't know how to get a reference to the jQuery calendar created by the Date module from my module.

Anyone have to do this before?

Comments

mtpultz’s picture

Figured it out. Took the jQuery instantiation code from Date module and put it in my module overwriting the original version and at the same time adding the bit of code I needed for the calendar field.

    drupal_add_js("
		Drupal.behaviors.date_popup = function (context) {
		  for (var id in Drupal.settings.datePopup) {
		    $('#'+ id).bind('focus', Drupal.settings.datePopup[id], function(e) {
		      if (!$(this).hasClass('date-popup-init')) {
		        var datePopup = e.data;

                        // MY ADDED CODE SEGMENT
		        datePopup.settings.beforeShowDay = function(date) { var day = date.getDay(); return [(day != 1 && day != 2 && day != 3 && day != 4 && day != 5), '']; }
		        
		        // Explicitely filter the methods we accept.
		        switch (datePopup.func) {
		          case 'datepicker':
		            $(this)
		              .datepicker(datePopup.settings)
		              .addClass('date-popup-init')
		            $(this).click(function(){
		              $(this).focus();
		            });
		            break;
		
		          case 'timeEntry':
		            $(this)
		              .timeEntry(datePopup.settings)
		              .addClass('date-popup-init')
		            $(this).click(function(){
		              $(this).focus();
		            });
		            break;
		        }
		      }
		    });
		  }
		};
    ",'inline');