When you create an AHAH form, and inside, return a new ahah button, the new button doesn't have a ahah behaviour.

I find this :

$javascript = drupal_add_js(NULL, NULL);
if (isset($javascript['setting'])) {
$output .= '

jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');

';
}

But this hack doesn't work for me.

Comments

rfay’s picture

Category: bug » support

Yes, you have to reattach the behavior in that case. The handbook has a workaround, if I remember right, in http://drupal.org/node/331941.

v-a-1’s picture

What the OP actually has attempted is what is mentioned in the handbook page you linked to.
My attempt was exactly the same as the OP and it doesn't work.
Any other ideas?

v-a-1’s picture

Figured out the correct way to do this:

  $output = theme('status_messages') . drupal_get_js() . drupal_render($form['form']['element']); 
  //the drupal_get_js() is very important for reattaching js behaviour to dynamically loaded form elements.

  drupal_json(array('status' => TRUE, 'data' => $output));
cweagans’s picture

Priority: Major » Normal

Support requests are never major or critical.

nakeddesign’s picture

Thank you 1000 times - Been smashing my head against the wall for days on this one.

drupal_get_js() worked a charm :)

nakeddesign’s picture

This worked for adding new AHAH elements but the get_js causes any custom drupal behaviors to fail.

v-a-1’s picture

Can you be more specific? What custom behaviours? Where are these set? In another module? In the core?

nakeddesign’s picture

If have have some jQuery on the same form, then after the callback does the drupal_get_js() the jQuery code no longer functions:

e.g. The following works before the ahah event but not after.

Drupal.behaviors.menu = function(context) {    
    $( ".someOtherNonAHAElement" ,context).click(function() {    
       do_somthing();
    });
}

If I remove the drupal_get_js() then the jQuery continues to function as expected after the ahah callback, but then of course any new ahah elements are not bound.

nakeddesign’s picture

No one come across this then?

rfay’s picture

Nobody's paying attention to D6...

nakeddesign’s picture

lol - I am!!

cweagans’s picture

Well stop it :) Drupal 7 is quite nice!

nakeddesign’s picture

We are actually migrating to D7 later this year, but we still have a few things to sort before hand so I'm hoping to get all the functionality finished in D6 this month and then we'll start the migration.

arulraj.m’s picture

Issue summary: View changes

Hi drupal_get_js() is working fine, but the following css are called many times.

/misc/jquery.cookie.js?v=1.0
/misc/jquery.form.js?v=2.52
/misc/ajax.js?v=7.28
/sites/all/modules/ajax_forms_test/ajax_forms_test.js?n7gjot
/sites/all/modules/meme_wall/js/meme_wall.js?n7gjot
/misc/progress.js?v=7.28
/sites/all/modules/flag/theme/flag.js?n7gjot
/misc/jquery.js?v=1.4.4
/misc/jquery.once.js?v=1.2
/misc/drupal.js?n7gjot

Thanks & regards,
Arulraj.m

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.