Towards an AHAH framework / automatic javascript generation

I have been having some really exciting ideas about getting the formAPI to generate the bindings to the javascript. I realized that all the javascript I wrote for the tutorial module could be generalized. Then with a bit of glue code, all of the parameters needed to do the event binding could be put in a properties set on the form element. This way Drupal coders could create modules with sophisticated AHAH effects without needing to write any Javascript at all. Here is an example of a button declaration with all of the info needed to do a incremental page update:

<?php
    $element
['new_subwidget']['add_subwidget_button'] = array (
       
'#type' => 'button',
       
'#value' => t( 'Add New Subwidget' ),
       
'#id' => 'widget_add_subwidget_button_' . $name,
       
'#ahah_bindings' => array (
                array(
                   
'wrapper' => 'widget_wrapper_' . $name,
                   
'event' => 'click',
                   
'path' => 'widget/widget_update_js',
                   
'params' => array( 'widget_name_js' => $name ),
                ),
          ),
    );
?>

I have rewritten my widget.module to use this generalized framework and it all works and is pretty simple. All the magic happens in the ahah.module, which is still a little clunky, but it works. I think this approach could make creating dynamically updating forms for Drupal much easier and more approachable. You still need to set up the php correctly, but you don’t have to wrap you brain around the js data model.

AttachmentSize
widget.zip14.08 KB