RSS

Newsletter

The CodeKarate Newsletter is the best way for technical ninjas to keep their swords sharpened. Don't worry, we won't flood your inbox and your email address will always remain private.
Back to Top

Removing the fieldset on a Drupal 7 date field

This is a relatively easy one, but I found myself scratching my head at this for longer than was necessary. There are times in which you do not want a Drupal 7 date field to be added inside a fieldset. One discussion on Drupal.org (http://drupal.org/node/1467712) mentions applying a patch to the Date module. I think it is much better to just use the theme layer for it's intended purpose... overriding theme-able output. The main problem for a lot of people, is that they are just not as comfortable with PHP or are unsure which functions need to be overridden in your template.php to get the desired results.

So if you are looking for the simplest way to get your Drupal 7 date fields from displaying inside of a Fieldset, drop this code into your theme's template.php file (replacing MYTHEME with the name of your theme).

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

Just for reference, the original theme function was called theme_date_combo and is located in the date.theme file of the date module. Here is the original code:

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));
}

It is almost too simple... you just need to know which function to override.

Discussions

1
Alex Weber (not verified)

Thanks

Great, thanks for sharing! Just complementing, if you need any help figuruing out what exactly is the theme function to override, take a look at Devel Themer: http://drupal.org/project/devel_themer its pretty slick!

1-1
shane

Great advice

Thanks for the tip. I have used it in the past with some success. It is probably something I should just turn on for all my development sites...

shane's picture
2
oadaeh (not verified)

More date field stripping

I had a similar need and approached it a differnt way. I wanted more stripped from the field and acheived it witth the combination of hook_form_alter() and CSS. Here's the issue where that discussion took place: https://drupal.org/node/1409374

3
Jeremy (not verified)

Amazing - thanks for this, so

Amazing - thanks for this, so easy!

4
Tyler (not verified)

This seems to do nothing for

This seems to do nothing for me...do I need to use a different function if I am using a date popup widget type?

4-1
shane

Should work

I think it should work. Might be good to try the module listed in the first comment to make sure you are using the correct theme function. Also never hurts to double check that you cleared the cache.

shane's picture
5
monsoon (not verified)

Hi, Thanks, this post has

Hi,
Thanks, this post has solved my problem, now the date fields are without fieldset.

I have similar issue with Location module which adds a fieldset around all the fields e.g. Location name, street, additional, city, state, country, phon no. etc.)
Please let me know how can I remove this fieldset?
Perhaps your code could do the magic again but needs some changes?

Thanks,

6
mahendran (not verified)

hi thanks

its too easy, i need to store only date and month in database how to do this

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <blockquote> <img>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <php>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <python>, <ruby>. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.