Friday, February 6, 2009

AHAH Helper Module For Drupal

The ahah helper module provides a neat function ‘ahah_helper_path’ to let drupal know about new field elements. This way you can set the path “magically” and the helper module takes care of how the new fields will be rendered. You can use it like this:


$form[’slide_form’][‘new_field’] = array
// field properties …
The ahah property path will be:
‘#ahah’ = array (
‘path’ => ahah_helper_path(array(’slide_form’, ‘new_field’)),
// other properties
);


This helper module makes it very easy to update a form with your own ajax-driven field addtions. It helps memorizing the form so your new fields are known by drupal. At the form api reference link, we can see which fields can trigger this behavior: button, checkbox, image button, password, radio, select, submit, textarea, textfield.

An extra advantage of using the ahah helper module is that when javascript is disabled, the same function will be called with a normal post and this will work just fine. Sometimes it can be helpfull to check #first_time parameters in callbacks to see if the data was previously saved.

No comments: