Closed (fixed)
Project:
AHAH Forms Framework
Version:
5.x-1.5-3
Component:
Code
Priority:
Minor
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Apr 2007 at 08:21 UTC
Updated:
3 May 2007 at 18:01 UTC
function ahah_simple_menu($may_cache) {
$items = array();
if (!$may_cache) {
$items[] = array(
'path' => 'ahah/simple',
'title' => t('Ahah Simple'),
'callback' => 'drupal_get_form',
'callback arguments' => array('ahah_simple_page'),
'access' => TRUE,
);
$items[] = array(
'path' => 'ahah/simple_js',
'title' => t('Never seen'),
'callback' => 'ahah_simple_js',
'type' => MENU_CALLBACK,
'access' => TRUE,
);
}
return $items;
}
function ahah_simple_page() {
$form = array();
$form['target'] = array(
'#type' => 'item',
'#value' => "Don't do it!",
'#prefix' => '<div id="target">',
'#suffix' => '</div>',
);
$form['submit'] = array(
'#type' => 'button',
'#value' => t('Click Me'),
'#ahah_bindings' => array (
array(
'event' => 'click',
'path' => 'ahah/simple_js',
'wrapper' => 'target'
)) ,
);
return $form;
}
function ahah_simple_js() {
print '<p>No one ever listens.</p>';
}
I've made some very minor changes as you can see which should not affect the functionality of this module, but which make it slightly easier to use (having a title for the path means that it shows up in the menu for instance).
My first suspicion was that the jQuery version you were using was different than mine, so I updated to v1.6 (of the Drupal version of jQuery).
My second suspicion was that I needed to adjust the paths, so I tried using url('ahah/simple_js'), but this doesn't seem to work either.
Once I can get the simple version to work, then I can use this module to extend one of my modules, which I am very excited about.
Thank you,
Dave
Comments
Comment #1
dwees commentedForgot URL to problem site. It is: http://www.unitorganizer.com/drupal5/ahah/simple
Thanks again.
David Wees
Comment #2
starbow commentedI think you might have come across a small bug in the simple example. Since submit buttons do not automatically get an id, the binding tries to use the submit class, which only works if it is the only submit button on the page. Try this change
$form['submit'] = array(
'#type' => 'button',
'#value' => t('Click Me'),
'#attributes' => array( 'id' => 'simple_submit' ),
'#ahah_bindings' => array (
array(
'event' => 'click',
'path' => 'ahah/simple_js',
'wrapper' => 'target'
)) ,
);
I don't know if that will work, but if it does, let me know and I will roll it into the module.
Comment #3
dwees commentedFound a fun fact about the forms API which makes the ID attribute very interesting. It has an #id attribute which and you can set an 'id' attribute, and the '#id' attribute of the form is set to 'edit-submit' for a submit button, and I set the 'id' attribute to 'simple_submit' as suggested. As a result the HTML id of the submit button is 'simple_submit' but the internal id which your module reads is 'edit-submit' so after your change, the example still wasn't working.
I can't just set the '#id' attribute because this is used internally only, so I have to set both. Code example below, and this works on my site now.
I'm not sure if I'm supposed to be able to set the internal '#id' element of the form, but whatever it works.
Comment #4
starbow commentedYeah, the proper use of #id is a little unclear. I just tested it with just the #id, no #attributes, and that seems to work fine, so I will update ahah_simple.module.
cheers,
-tao
Comment #5
(not verified) commented