You are here

function date_popup_elements in Date 6

Same name and namespace in other branches
  1. 5.2 date_popup/date_popup.module \date_popup_elements()
  2. 6.2 date_popup/date_popup.module \date_popup_elements()

Implementation of hook_elements().

Set the #type to date_popup and fill the element #default_value with a date adjusted to the proper local timezone in datetime format (YYYY-MM-DD HH:MM:SS).

The element will create two textfields, one for the date and one for the time. The date textfield will include a jQuery popup calendar date picker, and the time textfield uses a jQuery timepicker.

NOTE - Converting a date stored in the database from UTC to the local zone and converting it back to UTC before storing it is not handled by this element and must be done in pre-form and post-form processing!!

#date_timezone The local timezone to be used to create this date.

#date_format The #date_format parts can be in any order, and use any of the normal separators, but are limited to the following formats: Y, m, d, H, h, i, s, a

So valid formats include: Y-m-d H:i m/d/Y h:ia

Invalid formats include things like: m/j/y G:i

#date_increment Increment minutes and seconds by this amount, default is 1.

#date_year_range The number of years to go back and forward in a year selector, default is -3:+3 (3 back and 3 forward).

File

date_popup/date_popup.module, line 121
A module to enable jquery calendar and time entry popups. Requires the Date API.

Code

function date_popup_elements() {
  return array(
    'date_popup' => array(
      '#input' => TRUE,
      '#tree' => TRUE,
      '#date_timezone' => date_default_timezone_name(),
      '#date_format' => variable_get('date_format_short', 'm/d/Y - H:i'),
      '#date_increment' => 1,
      '#date_year_range' => '-3:+3',
      '#process' => array(
        'date_popup_process',
      ),
      '#element_validate' => array(
        'date_popup_validate',
      ),
    ),
  );
}