So, I don't really want the #description for my field to read "Format: 2008-8-11," but I can't figure out how to override it. Personally, I don't think this module should be automatically providing field descriptions at all, but maybe that's just me...

Comments

KarenS’s picture

Version: 6.x-2.0-beta4 » 6.x-2.x-dev
Category: support » feature

That's done because with a text field you need to give the user an idea of what they are expected to provide, since dates can be in so many possible formats.

But I agree it's reasonable to allow for a way to override that, so this is a feature request. Feature requests go against the -dev version, so I'm changing that.

tirdadc’s picture

Chiming in to say this feature would be nice to have. I initially figured I'd be able to modify it with a hook_form_alter(), but that didn't work given the setup with date_popup_elements().

ohthehugemanatee’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev

Noting that this applies to 7.x as well. There's an expectation that a form element's description can be overridden with hook_form_alter on $form['fieldname']['#description'], but this doesn't work for date fields.

You CAN modify the description if you override $form_state['field']['fieldname']['und']['instance']['description'], but this is not normal. I'm not sure if this is a feature request or a low priority bug - field descriptions are SUPPOSED to be overrideable from the $form variable.

capellic’s picture

A bit surprised that this issue hasn't gotten more attention seeing as it breaks core functionality. If I enter a string for "Help text" on the field edit form, that text should appear as the description text on the node form. It should only be a question of whether or not the the "e.g." string should be appended to whatever the site builder adds or not, or if there is an option on the field edit form to allow the site builder to suppress it or allow it to append.

Here are some resources on how to overcome this bug:

http://drupal.stackexchange.com/questions/28228/how-to-remove-format-des...

http://www.webpixel.gr/blog/drupal/remove-format-description-in-date_pop...

capellic’s picture

Issue summary: View changes

While this resource (http://drupal.stackexchange.com/questions/28228/how-to-remove-format-des...) shows us how to remove the helper text added by the popup widget, it's this resource (http://drupal.stackexchange.com/questions/28228/how-to-remove-format-des...) that gets us on our way to applying the description text we have defined for the helper text.

In a custom module, add these two functions where 'mymodule' is substituted for your module machine name and 'content_type_machinename' is substituted for whatever your field collection machine name is.

/**
 * hook_element_alter_info()
 *
 * Added to overcome the inabiity to define help text for the Date Popup widgets.
 */
function mymodule_element_info_alter(&$type) {
  if (isset($type['date_popup'])) {
    $type['date_popup']['#process'][] = '_mymodule_date_popup_process';
  }
}


/**
 * Helper function to mymodule_element_info_alter which allows me to set the description field.
 */
function _mymodule_date_popup_process($element, $form_state, $complete_form) {
  $field_name = $element['#instance']['field_name'];
  $instance = field_info_instance('node', $field_name, 'content_type_machinename');
  $element['date']['#description'] = $instance['description'];

  return $element;
}

In my case, I needed a date field that was on a field collection which was attached to a content type. All you have to do is substitute the line with the call to field_info_instance() above with the one below where 'field_collection_machinename' is the machine name of your field collection.

$instance = field_info_instance('field_collection_item', $field_name, 'field_collection_machinename');
fonant’s picture

Capellic's code didn't work for me, but this did:

function mymodule_element_info_alter(&$type) {
  if (isset($type['date_popup'])) {
    $type['date_popup']['#process'][] = '_mymodule_date_popup_process';
  }
}

function _mymodule_date_popup_process($element, $form_state, $complete_form) {
  $element['date']['#description'] = $element['#instance']['description'];
  return $element;
}