[development] Question on AHAH
nitin gupta
nitingupta.iitg at gmail.com
Sat Apr 3 04:40:19 UTC 2010
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 at 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 at 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 at randyfay.com
> > +1 970.462.7450
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100403/a326b8c3/attachment-0001.html
More information about the development
mailing list