Thursday, October 21, 2010

Autocomplete paths and themes in Drupal

It is very important that any AHAH callback menu item is of the same theme loading menu execution path as that of the parent. Otherwise you will have themes conflicting and overriding each other.

Here's a case in point:

Say you are using 'rubik' theme for admin pages (node edit & add pages). And lets assume you are using Garland as the front end theme for other users.

If you happen to have an autocomplete or AHAH form element in the node edit page like so:
$form['book']['submit_book'] = array(
'#type' => 'submit',
'#value' => t('Select book'),
'#weight' => -4,
'#attributes' => array('class' => 'book-title-select'),
'#ahah' => array(
'path' => 'mybooks/js',
'wrapper' => 'edit-book-plid-wrapper',
'effect' => 'slide',
),
);

This will cause the Garland theme to be loaded to the current page when the AHAH callback 'mybooks/js' executes. If the callback happened to add new elements into the form, then they would be rendered in Garland. Not what you would really want! You could go around in circles with your UI team over this and waste a lot of time like I did!

No comments: