I have a custom field in a custom form element which is declared using the following code:

$element['data_da'] = array(
  '#type' => 'date',
  '#title' => t('Date from'),
  '#default_value' => isset($items[$delta]['data_da']) ? $items[$delta]['data_da'] : NULL,
  '#description' => t('Description for field Date from'),

When I insert data, I see three selects, one for year, one form month and one for day. I would like to use the "date_popup" widget.
How can I do that? What should I set? Is there a '#widget' directive?

1 Answer 1


If you install the version 2.x of the Date module, you will be able to use more form fields, including a "date_popup" field, which shows a pop-up to select the date.
The module has an option that allows the user to decide if the pop-up should be shown; if you want to override that option, you should use variable_set('date_popup_timepicker', 'default'). That is the default option used by the module, but if the user selects "none," then the pop-up will not appear.

About setting a custom format with the "date_popup" field, the form field uses the "#date_format" attribute that, in the development snapshot 7.x-2.x, is said to accept most of the formats. The default value for that attribute is the one returned by variable_get('date_format_short', 'm/d/Y - H:i').
The complete list of the attributes used by the form field, reported in a comment for the date_popup_element_info() documentation is the following one:

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

  • "#date_format"
    Unlike earlier versions of this popup, most formats will work.

  • "#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).

Drupal core modules have only the "date" form field, and it doesn't use any "#widget" attribute. Third-party modules could define new attributes, though; as far as I know, no module defines "#widget" as attribute for form fields.

  • Actually i'm using the Date module, i'd like to use the simple datepicker and set the format to dd/mm/YYYY. I f i choose date_popup it also shows a timepicker. And i don't know how to set the format (it defaults to mm/dd/YYYY Jul 25, 2011 at 12:28
  • I expanded my answer to report how to set a custom format.
    – apaderno
    Jul 25, 2011 at 12:44
  • 1
    kali-dasan.blogspot.in/2014/06/… - Here I have explained with example.
    – Kalidasan
    Jun 5, 2014 at 7:54
  • Is there any chances to set min and max date in #datepicker_options ?
    – Guru
    Aug 4, 2015 at 12:19
  • @Guru As far as I can see, no. #datepicker_options is for jQuery picker options.
    – apaderno
    Aug 4, 2015 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.