Forms with multiple dynamic expanding elements

yraber - August 17, 2007 - 06:15
Project:AHAH Forms Framework
Version:5.x-1.5-5
Component:Code
Category:support request
Priority:normal
Assigned:starbow
Status:closed
Description

Hello,

I'm playing with this wonderful framework for two days now, and it does a great job. But when trying to add two kind of dynamic expanding elements in a form, it breaks everything.

Maybe I'm just missing something obvious ,but I'm really stuck ... Do you have any example of this working ? I've watched the simple, todos and polls examples, but they don't help for this problem.

Thank you.

#1

yraber - August 20, 2007 - 17:34

#2

dayre - October 3, 2007 - 03:48
Status:active» needs review

I had an issue with attaching ahah bindings to a collection of checkbox form elements. Say i had checkboxes A, B, C and D. When i clicked on A, the ahah javascript properly sent the ajax request to the server. When i clicked on B, i got 2 requests... and C, got 3 requests. The issue was that everytime a "click" or "change" is triggered, the ahah javascript rebinds the click/change function calls to all the elements again. In order to prevent this accumulation of function calls, i had to insert jquery unbind() calls into the ahah_forms.js file. This removes any previous bindings and ensures only one click function associated with each element during every ajax call cycle:

$(key).each( function() {
// console.log( "Attaching:  " + el.id + " : " + el.event + " (" + el.wrapper +")" );
if( element.event === 'click' ) {
  $(this).unbind( "click" );
$(this).click( function() {Ahah.update( element, this.id ); return false;} );
}
else if( element.event === 'change' ) {
  $(this).unbind("change");
$(this).change( function() {Ahah.update( element, this.id ); return false;} );
}
  } );

Not sure if this solves your particular problem, but it fixed one of my issues.

My other issue which i haven't resolved yet is i've got two forms on my page of checkboxes... when i add one form, everything works great, but the second form, the ajax submission process get's all screwd up and the ui updates get screwed up... still working on that one.

#3

dayre - October 3, 2007 - 04:14

I resolved my other problem with multiple forms on a page..... fix is here: http://drupal.org/node/180412

#4

dayre - October 3, 2007 - 04:21

One more comment....

Without this unbind() fix, some of you may be seeing slugish behavior in the browser when you have multiple form elements bound using ahah. This is due to the fact that multiple ajax calls are being made for the same form element trigger...

When unbind is added, things run smooth....

#5

yraber - October 3, 2007 - 19:56

This is exactly the problems I had.
For now I changed strategy and continued without dynamic forms, but I'll give a try at your patch when I'll have time.

#6

yraber - October 18, 2007 - 09:15

Great ! It's working ... finally :) Thank you so much.

I think it would be really nice to put this patch into the module distribution.

Cheers,

Yves.

#7

starbow - December 1, 2007 - 00:37
Assigned to:Anonymous» starbow

#8

starbow - July 21, 2009 - 21:10
Status:needs review» closed
 
 

Drupal is a registered trademark of Dries Buytaert.