Classes being overwritten by Ajax module

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by Janne Salo on February 8, 2010 at 9:20am

Hello,

I've been using the Ajax module a while now, and for the most part, it's really cool. One thing, however, is quite annoying.

Whenever I set a class attribute for an ajax-enabled form or its submit button, it gets overwritten by the module. This happens in functions ajax_validator_set, ajax_submitter_set (for forms) and ajax_submitter_find (for submit buttons). Instead of setting the class attribute, I suggest checking if there is a class set before and concatenate the 'ajax-form' or 'ajax-trigger' class to the element if that is the case.

For the submit buttons, I've been able to work around the issue by creating a theme function for the form in which I set the class. But for form attributes, this didn't seem to work the same way.

This is one way the problem can be fixed (mostly an example):

function ajax_submitter_set(&$form, $found) {
if (!$found['submitter']) {
$form['#submit'][] = 'ajax_submitter';

if (isset($form['#attributes']) && isset($form['#attributes']['class'])) {
//This check is needed in order to avoid duplicate 'ajax-form' classes
if (strpos($form['#attributes']['class'], 'ajax-form') === false) {
$form['#attributes']['class'] .= ' ajax-form';
}
}
else {
$form['#attributes']['class'] = 'ajax-form';
}
}
return TRUE;
}

Ajax.module

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /