Try http://pastie.org/517369

The code is untested but i cant forsee any problems...

Basically it creates an array called "cached" and everytime a click handler 
is added its id is added to the cached array.... Every time #add_edit_cats 
is clicked it checks the length of the array is greater than or equal to 1 
and if so it loops through the array and calls prototye's stopObserving() 
function on that element...

I clean up your code slightly as you said you were new to javascript / 
prototype ....

the main difference is removed Event.observe .. $(elem).observe...... does 
exatcly the same thing but its less code !!..

You will also notice var params=$(this).serialze(true); .... `this` is can 
be used in the scope because its observed and `this` is contained in the 
calling (it has a name but i cant remember what it is !!).... so any time 
you want to get the object or element when using observe you can use this 
`this` keyword (a little bit like php classes) ....

I would also recommend assigning your Ajax.Updater stuff to variables so 
they can be nulled when they are finished ... example: var req=new 
Ajax.Updater({..........................}); req=null; - this unloads some of 
it from client memory and makes for a faster application (tried and tested)

I cant see why there will be an infinite loop  but there is no point 
attaching more than one observer to a click if you dont need to (hence the 
stopObserving() )...

Anyway

HTH

ALex

.


----- Original Message ----- 
From: <ph...@ryangibbons.net>
To: "Prototype & script.aculo.us" <prototype-scriptaculous@googlegroups.com>
Sent: Friday, June 19, 2009 4:19 AM
Subject: [Proto-Scripty] Event.observe and Ajax.Updater recursion problems?


>
> Hey all,
>
> I will preface this with the fact that I am a new user of both
> prototype and javascript, so I am learning (slowly) as I go.  I am
> currently working on a blog interface and I was going to use this as
> my opportunity to learn prototype and some more dynamic ways to handle
> form data.
>
> That all being said I am running into problems on a "Select
> Categories" form that toggles between being editable and used to
> select the categories that apply to a blog post.  The best way to
> describe it is to show it to you: http://www.wiredphotographer.com/?s=new
> once you get there click on the "ADD / EDIT CATEGORIES" link in the
> bottom right.  Please note this is a rough draft of the site so not
> everything is functional and the code might not yet be as tidy as it
> should be.
>
> Anyways where I have problems are with event observers, I am finding
> that I would almost have to have an indefinite loop of onComplete
> followed by new observers.
>
> Here is the javascript that I have been toying with: 
> http://pastie.org/517240
>
> I know that it is not correct or "good" code and I know that the
> approach I am trying is probably fundamentally flawed.  So I am
> looking for someone that might be able to set me in the right direct.
>
> Thanks for all the help,
>
> Ryan
>
>
> >
> 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to