Not sure if this is a support request or feature request but I was just wondering if it is possible to remove the fieldset around the date fields in my node/add forms.. just looking for a cleaner look on a particular site.

Comments

joachim’s picture

Status: Active » Closed (fixed)

You can probably do it with hook_form_alter in a custom module, though note that CCK fields are largely not built by that point: you should register a callback for the #after_build step.

progkiller’s picture

but where should I remove it. It is not a separated fieldset that I can change the #access property to be disable.

seanbfuller’s picture

I was able to accomplish this using a theme override of theme_date_combo(). Place the following in your template.php file (notice I commented out the original code here):

/**
 * Theme date module's from/to date combination on form.
 * @see /sites/all/modules/date/date.theme function theme_date_combo()
 */
function YOURTHEMENAMEHERE_date_combo($vars) {

  // Override the display of the combo element
  $element = $vars['element'];
  return '<div class="date-combo-wrapper">'. $element['#children'] .'</div>';

  /* Original code
  $element = $vars['element'];
  $field = field_info_field($element['#field_name']);
  $instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
  if (!$field['settings']['todate']) {
    return $element['#children'];
  }
  // Group from/to items together in fieldset.
  $fieldset = array(
    '#title' => check_plain($instance['label']) . ' ' . ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''),
    '#value' => '',
    '#description' => $element['#fieldset_description'],
    '#attributes' => array(),
    '#children' => $element['#children'],
  );
  return theme('fieldset', array('element' => $fieldset));
  */
}

For my purposes, I used the field_group module to group some of the time elements that I was using. I didn't want the nested fieldsets, and this seems to be doing the trick so far.

pfrenssen’s picture

Here's how you can do it with a form alter hook in D7:

This changes the fieldset for the 'field_event_date' field to a regular div.

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MYMODULE_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
  $form['#after_build'][] = 'MYMODULE_form_FORM_ID_hide_fieldsets';
}

/**
 * Helper function for MYMODULE_form_FORM_ID_alter().
 *
 * Hides the fieldsets of FORM_ID.
 */
function MYMODULE_form_FORM_ID_hide_fieldsets($form) {
  $form['field_event_date'][LANGUAGE_NONE][0]['#theme_wrappers'] = array('form_element');
  return $form;
}
geerlingguy’s picture

@pfrenssen / #4 - Thanks for the code—I was banging my head against a wall trying to improve the themeability of a single date field (no end date option, no all day option, etc., just a single date popup field with a label, and this was the missing link.

mrfelton’s picture

To get my date popup field to look exactly like all other fields, I used the following:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mytheme_form_user_profile_form_alter(&$form, $form_state, $form_id) {
  if ($form['#user_category'] == 'account') {
    // Add helper to remove the fieldset wrapper.
    $form['#after_build'][] = '_mytheme_form_user_profile_hide_fieldsets';
  }
}

/**
 * Helper function for mytheme_form_user_profile_form_alter().
 *
 * Hides the fieldsets of field_profile_dob.
 */
function _mytheme_form_user_profile_hide_fieldsets($form) {
  $form['field_profile_dob'][LANGUAGE_NONE][0]['#theme_wrappers'] = array('form_element');
  $form['field_profile_dob'][LANGUAGE_NONE][0]['value']['#theme_wrappers'] = array();
  unset($form['field_profile_dob'][LANGUAGE_NONE][0]['value']['#wrapper_attributes']);
  unset($form['field_profile_dob'][LANGUAGE_NONE][0]['value']['date']['#title']);
  return $form;
}
hlopes’s picture

Using that as-is in D7 throws a in_array warning.

Using

$form['#after_build'][] = 'MYMODULE_form_FORM_ID_hide_fieldsets';

instead of

$form['#after_build'] = 'MYMODULE_form_FORM_ID_hide_fieldsets';

should prevent that.

pfrenssen’s picture

Thanks, I updated my post.

Angry Dan’s picture

I've been trying to do this all day! I'm editing node_form and I only needed this line in the end:
$form['{FIELDNAME}'][LANGUAGE_NONE][0]['#theme_wrappers'] = array('form_element');
Thanks!

dalegrebey’s picture

This will remove the date fieldset from the date module. Add this to your template.php file.

function MYTHEME_date_combo($variables) {
  return theme('form_element', $variables);
}