When using the date_select element in a form definition without a #default_value, an undefined index warning is produced:

'Notice: Undefined index: #default_value in date_select_element_process() (line 462 of /sites/all/modules/contrib/date/date_api/date_api_elements.inc)

Sample code:

$form['subscribe']['date'] = array(
    '#type' => 'date_select',
    '#title' => t('Date'),
    '#date_format' => 'F-d-Y',
    '#date_year_range' => '0:+1',
    '#date_label_position' => 'within',
    '#validated' => TRUE,
);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ebeyrent’s picture

gaurav.goyal’s picture

This bug was also there in the Date 7.x-2.6 Version, Above patch #1 solves the problem. But there was an error in apply the patch

date_api_elements-2204713-1.patch:10: trailing whitespace.
if (array_key_exists('#default_value', $element) && is_array($element['#default_value'])) {
warning: 1 line adds whitespace errors.

Just added a little to it, now it can be applied, attached is the patch.

BR0kEN’s picture

Title: Undefined index » Undefined index #default_value in date_select_element_process
Version: 7.x-2.7 » 7.x-2.x-dev
Status: Active » Needs review
BR0kEN’s picture

jstoller’s picture

The patch in #2 fixes the problem, but doesn't apply properly since the paths are off. The attached patch will apply from the module's root directory.

The patch in #5 seems to work as well, but it makes a bunch of apparently unrelated changes with no explanation, so I'm avoiding it for now.

jstoller’s picture

Status: Needs review » Reviewed & tested by the community

I've been using this for two years now, so seems safe to commit.

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks.

Status: Fixed » Closed (fixed)

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