The more complex a form in Drupal the more likely it will use Javascript to collapse certain sections.
In many ways it’s a good thing for usability as the submit and preview buttons are at the bottom of a form and the less scrolling down to reach these the better.

However, the other day on one of my sites I was using a prototype.js JavaScript framework and I noticed it was clashing with the collapse.js file and causing the collapsible sections to be unavailable.

I wanted keep this extra Javascript on the site as it was there for a useful purpose (I’ll be revealing all soon!) but not being that proficient with this client-side language I needed a way of dealing with the bug without tampering with Javascript.

The hack was actually pretty simple. I merely changed a name of HTML class in the core files so that it read “no” (I could have written anything) rather than “collapsed”:

function phptemplate_fieldset($element) {
if (!empty($element[‘#collapsible’])) {
drupal_add_js(‘misc/collapse.js’);

if (!isset($element[‘#attributes’][‘class’])) {
$element[‘#attributes’][‘class’] = ”;
}

$element[‘#attributes’][‘class’] .= ‘ collapsible’;

if (!empty($element[‘#collapsed’])) {
$element[‘#attributes’][‘class’] .= ‘ no’;
}
}

return ‘<fieldset’. drupal_attributes($element[‘#attributes’]) .’>’. ($element[‘#title’] ? ‘
‘. $element[‘#title’] .’

‘ : ”) . (isset($element[‘#description’]) && $element[‘#description’] ? ‘

‘. $element[‘#description’] .’

‘ : ”) . (!empty($element[‘#children’]) ? $element[‘#children’] : ”) . (isset($element[‘#value’]) ? $element[‘#value’] : ”) .”

n”;
}

The actual function is called theme_fieldset() and it can be found in form.inc. I renamed the function phptemplate_fieldset() to override it and placed it in the template.php file.
Now no Javascript collapsible boxes are enacted on any form in Drupal.

Leave a Reply

Your email address will not be published. Required fields are marked *