Remove fieldset on a date field Drupal 7

For some reason you want to display the date field without the fieldset wrapper, it’s not difficult but it may take you time to notice that the theme function called is in the date.theme file (date module) :

/**
 * Returns HTML for a start/end date combination on form.
 */
function theme_date_combo($variables) {
  $element = $variables['element'];
  $field = field_info_field($element['#field_name']);
  $instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
 
  // Group start/end items together in fieldset.
  $fieldset = array(
    '#title' => t($element['#title']) . ' ' . ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''),
    '#value' => '',
    '#description' => !empty($element['#fieldset_description']) ? $element['#fieldset_description'] : '',
    '#attributes' => array(),
    '#children' => $element['#children'],
  );
  return theme('fieldset', array('element' => $fieldset));
}

So to override the funtion and change the render of the field put this code in the template.php file of your theme :

/**
 * Render date field without fieldset
 */
function MYTHEME_date_combo($variables) {
  return theme('form_element', $variables);
}

Nice coding!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s