How difficult would it be to add a data picker (little calendar) to the event module? Instead of using the multiple pull-down selectors to pick date and time for an event, the user would click on a little calendar and select the date graphically.

Thanks,

Leo

AttachmentSize
jscalendar.module.txt1.27 KB

Comments

robertdouglass’s picture

This is designed to work with jscalendar-1.0.

Get the above package, add this code to your template.php file (PHPTemplate themes, create the file if it doesn't exist), find the theme function that calls the event widget currently... some assembly needed.

function theme_jscalendar($title, $name, $value, $description, $format) {
	static $load = TRUE;
	
	if ($load) {
	  $jsc_path = drupal_get_path('module', 'jscalendar');
    $jsc_path .= '/jscalendar-1.0';
	  theme_add_style("$jsc_path/calendar-win2k-1.css");
    drupal_set_html_head('<s cript type="text/javascript" src="'. $jsc_path.'/calendar.js"></s cript>');
    drupal_set_html_head('<s cript type="text/javascript" src="'. $jsc_path.'/lang/calendar-en.js"></s cript>');
    drupal_set_html_head('<s cript type="text/javascript" src="'. $jsc_path.'/calendar-setup.js"></s cript>');
  
    $load = FALSE;
  }

  $markup = <<<__JS__
<s cript type="text/javascript">
  Calendar.setup(
    {
      inputField  : 'edit-$name',         // ID of the input field
      ifFormat    : '$format',    // the date format
      trigger     : "button-$name",
      event       : 'click'
    }
  );
</s cript>
__JS__;

  $form['jscalendar'] = array('#type' => 'textfield', '#title' => $title, '#default_value' => $value, '#description' => $description, '#markup' => $markup);
  return $form;
}

Note that this is for 4.7 and that the s cript tags are deliberately broken to fool the suspicious content filter on Drupal.org (isn't there a better way???)

- Robert Douglass

-----
My sites: HornRoller.com, RobsHouse.net

nedjo’s picture

There's now an easy to use Jscalendar implementation in the Javascript Tools module. Enable the module and then add a 'jscalendar' class to a textfield.