If I'm not mistaken, the problem is that the AHAH bindings are done at page load time, and of course you're replacing the element that's bound with another element without a page reload, but the javascript does not know that you've changed things underneath it. <br>
<br>I don't know a way to introduce a new element and have it bound as an AHAH element. However, you could have both on the original page, with one hidden, and that would probably work.<br><br>In D7, you could probably find some ways to work around this, although it would still require some magic. <br>
<br>-Randy<br><br><div class="gmail_quote">On Fri, Apr 2, 2010 at 3:29 PM, nitin gupta <span dir="ltr"><<a href="mailto:nitingupta.iitg@gmail.com">nitingupta.iitg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi,<br><br>I have been scratching my head for long, looks like cant figure it out. If I add elements to the form on an AHAH refresh, let us say a submit button with AHAH properties, this button will not be submitted using AHAH. Anyone know about this? any pointers to resources? any work around?<br>
<br><br>function test_form($form_state) {<br> $form['open'] = array('#value' => '<div id="test_replace">');<br> dpm($form_state);<br> if($form_state['test'] == 1) {<br>
$form['test']['share'] = array(<br> '#type' => 'submit',<br> '#value' => 'share',<br> '#submit' => array('test_form_js_submit'),<br>
'#ahah' => array(<br>
'path' => 'test/js',<br> 'wrapper' => 'test_replace'<br> ));<br> }<br> else {<br> $form['test']['share2'] = array(<br> '#type' => 'submit',<br>
'#value' => 'share2',<br> '#submit' => array('test_form_js_submit'),<br> '#ahah' => array(<br> 'path' => 'test/js',<br> 'wrapper' => 'test_replace'<br>
));<br> }<br> <br> $form['close'] = array('#value' => '</div>');<br> <br> return $form; <br>}<br><br>function test_form_js_submit(&$form, &$form_state) {<br><br> $form_state['test'] = 1 ;<br>
$form_state['rebuild'] = TRUE;<br>}<br><br>function test_form_js() {<br> $form_state = array('submitted' => FALSE);<br> $form_build_id = $_POST['form_build_id'];<br> $form = form_get_cache($form_build_id, $form_state);<br>
$form_state['post'] = $form['#post'] = $_POST;<br> $form['#programmed'] = $form['#redirect'] = FALSE;<br> $args = $form['#parameters'];<br> $form_id = array_shift($args);<br> drupal_process_form($form_id, $form, $form_state);<br>
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);<br><br> //Get HTML for the replacement form. Only these elements will be AHAH-refreshed.<br> test_add_children($new_form['test'], $form['test']);<br>
$output = theme('status_messages') . drupal_render($new_form);<br> drupal_json(array('status' => TRUE, 'data' => $output));<br>}<br><br>function test_add_children(&$new_form, $form) {<br>
foreach (element_children($form) as $child) {<br> $new_form[$child] = $form[$child];<br> test_add_children($new_form[$child], $form[$child]);<br> }<br>}<br><br>function test_menu() {<br>$items = array();<br><br>
$items['test'] = array(<br>
$items['test/js'] = array(<br> 'page callback' => 'test_form_js',<br> 'type' => MENU_CALLBACK,<br> );<br><br> return $items;<br><br>}<br><br><br>In the above code, when 'share2' is clicked it submits perfectly using ahah, and converts to 'share' but this button does not have ahah properties.<br>
<font color="#888888">
<br clear="all">--<br>Regards,<br>Nitin Kumar Gupta<br><a href="http://publicmind.in/blog/" target="_blank">http://publicmind.in/blog/</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Randy Fay<br>Drupal Development, troubleshooting, and debugging<br><a href="mailto:randy@randyfay.com">randy@randyfay.com</a><br>+1 970.462.7450<br><br>