2

I am trying to remove the <fieldset> surrounding a date popup field, but I find that the label is also removed. This is my code:

function mymodule_profile_form_alter(&$form, $form_state, $form_id) {

  global $user;
  //print_r($form['field_last_name']);

  $form['field_birthdate']['und'][0]['#theme_wrappers']=$form['field_birthdate']['und'][0]['#theme_wrappers'][0];
}

Can anyone help me to solve this problem?

4
  • 1
    If you dont want the fieldset at all what about removing it from the theme altogether i.e. so it doesnt get generated?
    – Alex Gill
    Commented Dec 5, 2012 at 15:03
  • could you please tell me the code to remove the field set and tell me where can i type it and thanks Commented Dec 5, 2012 at 15:08
  • Are you sure your using date popup because this should theme as a form_element?
    – Alex Gill
    Commented Dec 5, 2012 at 15:46
  • There is a patch which brings option to render date field as normal textfield: http://drupal.org/node/1467712#comment-6137556 But in some cases fieldset is required and redner it as texfield may cause some problems.
    – fadehelix
    Commented Dec 5, 2012 at 15:47

1 Answer 1

3

Typically there is a theme function associated with the different sort of output you can give data fields or indeed any fields If you want to change this you do so on the theme level by overriding the default theme function in your themes template.php file.

Date popup

function YOURTHEME_date_popup($vars) {
  $element = $vars['element'];
  $attributes = !empty($element['#wrapper_attributes']) ? $element['#wrapper_attributes'] : array('class' => array());
  $attributes['class'][] = 'container-inline-date';
  // If there is no description, the floating date elements need some extra padding below them.
  $wrapper_attributes = array('class' => array('date-padding'));
  if (empty($element['date']['#description'])) {
    $wrapper_attributes['class'][] = 'clearfix';
  }
  // Add an wrapper to mimic the way a single value field works, for ease in using #states.
  if (isset($element['#children'])) {
    $element['#children'] = '<div id="' . $element['#id'] . '" ' . drupal_attributes($wrapper_attributes) .'>' . $element['#children'] . '</div>';
  }
  return '<div ' . drupal_attributes($attributes) .'>' . theme('form_element', $element) . '</div>';
}

Although it must be said this is being themed as a form_element so there is no fieldset.

Date combo is themed as a fieldset and again can be overriden...

function YOURTHEME_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'],
    );

    // Fix required marker.
    if ($element['#required']) {
        $fieldset['#title'] .= " " . theme('form_required_marker');
    }
    return theme('fieldset', array('element' => $fieldset));
}

If you replaced 'fieldset' with 'form_element' this would work.

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.