Hi, 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? function test_form($form_state) { $form['open'] = array('#value' => '<div id="test_replace">'); dpm($form_state); if($form_state['test'] == 1) { $form['test']['share'] = array( '#type' => 'submit', '#value' => 'share', '#submit' => array('test_form_js_submit'), '#ahah' => array( 'path' => 'test/js', 'wrapper' => 'test_replace' )); } else { $form['test']['share2'] = array( '#type' => 'submit', '#value' => 'share2', '#submit' => array('test_form_js_submit'), '#ahah' => array( 'path' => 'test/js', 'wrapper' => 'test_replace' )); } $form['close'] = array('#value' => '</div>'); return $form; } function test_form_js_submit(&$form, &$form_state) { $form_state['test'] = 1 ; $form_state['rebuild'] = TRUE; } function test_form_js() { $form_state = array('submitted' => FALSE); $form_build_id = $_POST['form_build_id']; $form = form_get_cache($form_build_id, $form_state); $form_state['post'] = $form['#post'] = $_POST; $form['#programmed'] = $form['#redirect'] = FALSE; $args = $form['#parameters']; $form_id = array_shift($args); drupal_process_form($form_id, $form, $form_state); $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); //Get HTML for the replacement form. Only these elements will be AHAH-refreshed. test_add_children($new_form['test'], $form['test']); $output = theme('status_messages') . drupal_render($new_form); drupal_json(array('status' => TRUE, 'data' => $output)); } function test_add_children(&$new_form, $form) { foreach (element_children($form) as $child) { $new_form[$child] = $form[$child]; test_add_children($new_form[$child], $form[$child]); } } function test_menu() { $items = array(); $items['test'] = array( $items['test/js'] = array( 'page callback' => 'test_form_js', 'type' => MENU_CALLBACK, ); return $items; } 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. -- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
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. 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. In D7, you could probably find some ways to work around this, although it would still require some magic. -Randy On Fri, Apr 2, 2010 at 3:29 PM, nitin gupta <nitingupta.iitg@gmail.com>wrote:
Hi,
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?
function test_form($form_state) { $form['open'] = array('#value' => '<div id="test_replace">'); dpm($form_state); if($form_state['test'] == 1) { $form['test']['share'] = array( '#type' => 'submit', '#value' => 'share', '#submit' => array('test_form_js_submit'), '#ahah' => array( 'path' => 'test/js', 'wrapper' => 'test_replace' )); } else { $form['test']['share2'] = array( '#type' => 'submit', '#value' => 'share2', '#submit' => array('test_form_js_submit'), '#ahah' => array( 'path' => 'test/js', 'wrapper' => 'test_replace' )); }
$form['close'] = array('#value' => '</div>');
return $form; }
function test_form_js_submit(&$form, &$form_state) {
$form_state['test'] = 1 ; $form_state['rebuild'] = TRUE; }
function test_form_js() { $form_state = array('submitted' => FALSE); $form_build_id = $_POST['form_build_id']; $form = form_get_cache($form_build_id, $form_state); $form_state['post'] = $form['#post'] = $_POST; $form['#programmed'] = $form['#redirect'] = FALSE; $args = $form['#parameters']; $form_id = array_shift($args); drupal_process_form($form_id, $form, $form_state); $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
//Get HTML for the replacement form. Only these elements will be AHAH-refreshed. test_add_children($new_form['test'], $form['test']); $output = theme('status_messages') . drupal_render($new_form); drupal_json(array('status' => TRUE, 'data' => $output)); }
function test_add_children(&$new_form, $form) { foreach (element_children($form) as $child) { $new_form[$child] = $form[$child]; test_add_children($new_form[$child], $form[$child]); } }
function test_menu() { $items = array();
$items['test'] = array( $items['test/js'] = array( 'page callback' => 'test_form_js', 'type' => MENU_CALLBACK, );
return $items;
}
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.
-- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
-- Randy Fay Drupal Development, troubleshooting, and debugging randy@randyfay.com +1 970.462.7450
This should be working. But you need indeed to tell ahah about the new form. Did you follow the descriptions on http://drupal.org/node/331941? Have a look at the quicktabs_ahah() function and the usage of $javascript['setting']. If I remember correctly than this is one of the keys to introduce your dynamic elements and register their behaviors. best regards, hadubard Am 03.04.2010 um 03:21 schrieb Randy Fay:
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.
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.
In D7, you could probably find some ways to work around this, although it would still require some magic.
-Randy
On Fri, Apr 2, 2010 at 3:29 PM, nitin gupta <nitingupta.iitg@gmail.com> wrote: Hi,
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?
function test_form($form_state) { $form['open'] = array('#value' => '<div id="test_replace">'); dpm($form_state); if($form_state['test'] == 1) { $form['test']['share'] = array( '#type' => 'submit', '#value' => 'share', '#submit' => array('test_form_js_submit'), '#ahah' => array( 'path' => 'test/js', 'wrapper' => 'test_replace' )); } else { $form['test']['share2'] = array( '#type' => 'submit', '#value' => 'share2', '#submit' => array('test_form_js_submit'), '#ahah' => array( 'path' => 'test/js', 'wrapper' => 'test_replace' )); }
$form['close'] = array('#value' => '</div>');
return $form; }
function test_form_js_submit(&$form, &$form_state) {
$form_state['test'] = 1 ; $form_state['rebuild'] = TRUE; }
function test_form_js() { $form_state = array('submitted' => FALSE); $form_build_id = $_POST['form_build_id']; $form = form_get_cache($form_build_id, $form_state); $form_state['post'] = $form['#post'] = $_POST; $form['#programmed'] = $form['#redirect'] = FALSE; $args = $form['#parameters']; $form_id = array_shift($args); drupal_process_form($form_id, $form, $form_state); $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
//Get HTML for the replacement form. Only these elements will be AHAH-refreshed. test_add_children($new_form['test'], $form['test']); $output = theme('status_messages') . drupal_render($new_form); drupal_json(array('status' => TRUE, 'data' => $output)); }
function test_add_children(&$new_form, $form) { foreach (element_children($form) as $child) { $new_form[$child] = $form[$child]; test_add_children($new_form[$child], $form[$child]); } }
function test_menu() { $items = array();
$items['test'] = array( $items['test/js'] = array( 'page callback' => 'test_form_js', 'type' => MENU_CALLBACK, );
return $items;
}
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.
-- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
-- Randy Fay Drupal Development, troubleshooting, and debugging randy@randyfay.com +1 970.462.7450
Thanks Randy, I think this is the time I should use the '#access' property for these elements. I can create all the elements at first page load and then toggle whatever I need using the '#access' property. -- Regards, Nitin Kumar Gupta http://publicmind.in/blog/ On Sat, Apr 3, 2010 at 7:05 AM, Hadubard <hadubard@gmail.com> wrote:
This should be working. But you need indeed to tell ahah about the new form. Did you follow the descriptions on http://drupal.org/node/331941? Have a look at the quicktabs_ahah() function and the usage of $javascript['setting']. If I remember correctly than this is one of the keys to introduce your dynamic elements and register their behaviors.
best regards, hadubard
Am 03.04.2010 um 03:21 schrieb Randy Fay:
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.
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.
In D7, you could probably find some ways to work around this, although it would still require some magic.
-Randy
On Fri, Apr 2, 2010 at 3:29 PM, nitin gupta <nitingupta.iitg@gmail.com> wrote: Hi,
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?
function test_form($form_state) { $form['open'] = array('#value' => '<div id="test_replace">'); dpm($form_state); if($form_state['test'] == 1) { $form['test']['share'] = array( '#type' => 'submit', '#value' => 'share', '#submit' => array('test_form_js_submit'), '#ahah' => array( 'path' => 'test/js', 'wrapper' => 'test_replace' )); } else { $form['test']['share2'] = array( '#type' => 'submit', '#value' => 'share2', '#submit' => array('test_form_js_submit'), '#ahah' => array( 'path' => 'test/js', 'wrapper' => 'test_replace' )); }
$form['close'] = array('#value' => '</div>');
return $form; }
function test_form_js_submit(&$form, &$form_state) {
$form_state['test'] = 1 ; $form_state['rebuild'] = TRUE; }
function test_form_js() { $form_state = array('submitted' => FALSE); $form_build_id = $_POST['form_build_id']; $form = form_get_cache($form_build_id, $form_state); $form_state['post'] = $form['#post'] = $_POST; $form['#programmed'] = $form['#redirect'] = FALSE; $args = $form['#parameters']; $form_id = array_shift($args); drupal_process_form($form_id, $form, $form_state); $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
//Get HTML for the replacement form. Only these elements will be AHAH-refreshed. test_add_children($new_form['test'], $form['test']); $output = theme('status_messages') . drupal_render($new_form); drupal_json(array('status' => TRUE, 'data' => $output)); }
function test_add_children(&$new_form, $form) { foreach (element_children($form) as $child) { $new_form[$child] = $form[$child]; test_add_children($new_form[$child], $form[$child]); } }
function test_menu() { $items = array();
$items['test'] = array( $items['test/js'] = array( 'page callback' => 'test_form_js', 'type' => MENU_CALLBACK, );
return $items;
}
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.
-- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
-- Randy Fay Drupal Development, troubleshooting, and debugging randy@randyfay.com +1 970.462.7450
nitin gupta wrote:
Thanks Randy, I think this is the time I should use the '#access' property for these elements. I can create all the elements at first page load and then toggle whatever I need using the '#access' property.
You might also be interested in http://drupal.org/project/ahah_helper for your ahah work. -- Earnie -- http://progw.com -- http://www.for-my-kids.com
Thanks Earnie, But I am looking to remove the dependency of ahah_helper from the project Facebook-style Links <http://drupal.org/project/facebook_link>. -- Regards, Nitin Kumar Gupta http://publicmind.in/blog/ On Mon, Apr 5, 2010 at 5:23 PM, Earnie Boyd <earnie@users.sourceforge.net>wrote:
nitin gupta wrote:
Thanks Randy, I think this is the time I should use the '#access' property for these elements. I can create all the elements at first page load and then toggle whatever I need using the '#access' property.
You might also be interested in http://drupal.org/project/ahah_helper for your ahah work.
-- Earnie -- http://progw.com -- http://www.for-my-kids.com
nitin gupta wrote:
Thanks Earnie, But I am looking to remove the dependency of ahah_helper from the project Facebook-style Links <http://drupal.org/project/facebook_link>.
I be interested in hearing why. -- Earnie -- http://progw.com -- http://www.for-my-kids.com
Hi, It is just a personal decision. I think if this can be done easily using the native approach, why create a dependency? It also results in piling of issues regarding the dependencies in this project's issue queue. -- Regards, Nitin Kumar Gupta http://publicmind.in/blog/ On Mon, Apr 5, 2010 at 6:16 PM, Earnie Boyd <earnie@users.sourceforge.net>wrote:
nitin gupta wrote:
Thanks Earnie, But I am looking to remove the dependency of ahah_helper from the project Facebook-style Links <http://drupal.org/project/facebook_link>.
I be interested in hearing why.
-- Earnie -- http://progw.com -- http://www.for-my-kids.com
If anyone is interested in the solution, http://drupal.org/node/331941 and that solution came from ahah_helper.module lines 193-201 (http://j.mp/de3uqv ). -- Regards, Nitin Kumar Gupta http://publicmind.in/blog/ On Mon, Apr 5, 2010 at 6:34 PM, nitin gupta <nitingupta.iitg@gmail.com>wrote:
Hi,
It is just a personal decision. I think if this can be done easily using the native approach, why create a dependency? It also results in piling of issues regarding the dependencies in this project's issue queue.
-- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
On Mon, Apr 5, 2010 at 6:16 PM, Earnie Boyd <earnie@users.sourceforge.net>wrote:
nitin gupta wrote:
Thanks Earnie, But I am looking to remove the dependency of ahah_helper from the project Facebook-style Links <http://drupal.org/project/facebook_link>.
I be interested in hearing why.
-- Earnie -- http://progw.com -- http://www.for-my-kids.com
participants (4)
-
Earnie Boyd -
Hadubard -
nitin gupta -
Randy Fay