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
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!
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...
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
Amazing - thanks for this, so
Amazing - thanks for this, so easy!
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?
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.
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,
hi thanks
its too easy, i need to store only date and month in database how to do this
Post new comment