Hi, i''m using (the awesome!) Form.Observe method. but here''s the thing- once the form has changed, i don''t need the observer anymore and i want to stop it. i tried different approaches, to no avail. any idea how to do that? here''s the code: var fo = new Form.Observer(document.forms[0], 2, formChanged); // init on load function formChanged() { $(''notice'').update(''The configuration has changed. Please save your changes.'') } Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
somebody...? On Mar 11, 4:23 pm, "bucktus" <ohada...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > i''m using (the awesome!) Form.Observe method. > but here''s the thing- > once the form has changed, i don''t need the observer anymore and i > want to stop it. > i tried different approaches, to no avail. > any idea how to do that? > > here''s the code: > > var fo = new Form.Observer(document.forms[0], 2, formChanged); // init > on load > function formChanged() { > $(''notice'').update(''The configuration has changed. Please save your > changes.'') > > } > > Thanks!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Mar-12 08:41 UTC
Re: Stop observing wirh Form.Observer (proto 1.5)
Hey, Since there currently is no cancel/stop facility in Form.Observer, your only shot is to use some variable accessible by your callback, that toggles it off after the first shot, e.g. var formChanged = function() { if (arguments.callee.notAnymore) return; // ... arguments.callee.notAnymore = true; } formChanged.prototype.notAnymore = false; new Form.Observer(''formId'', 2, formChanged); (yes, function prototypes can be used to store "function-static" variables... You''ll see this trick here and there in Prototype''s source code). -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Cheers. thanks. On Mar 12, 10:41 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hey, > > Since there currently is no cancel/stop facility in Form.Observer, your > only shot is to use some variable accessible by your callback, that > toggles it off after the first shot, e.g. > > var formChanged = function() { > if (arguments.callee.notAnymore) return; > // ... > arguments.callee.notAnymore = true;} > > formChanged.prototype.notAnymore = false; > > new Form.Observer(''formId'', 2, formChanged); > > (yes, function prototypes can be used to store "function-static" > variables... You''ll see this trick here and there in Prototype''s source > code). > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Cheers. thanks. On Mar 12, 10:41 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hey, > > Since there currently is no cancel/stop facility in Form.Observer, your > only shot is to use some variable accessible by your callback, that > toggles it off after the first shot, e.g. > > var formChanged = function() { > if (arguments.callee.notAnymore) return; > // ... > arguments.callee.notAnymore = true;} > > formChanged.prototype.notAnymore = false; > > new Form.Observer(''formId'', 2, formChanged); > > (yes, function prototypes can be used to store "function-static" > variables... You''ll see this trick here and there in Prototype''s source > code). > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
You could also put the following into a file you include after prototype.js: Object.extend(Form.Observer.prototype, { registerCallback: function() { this.intervalId = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); }, stop: function() { if (this.intervalId) clearInterval(this.intervalId); } } then you would be able to call fo.stop() -Tobias On 12 Mar., 16:55, "bucktus" <ohada...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Cheers. > thanks. > > On Mar 12, 10:41 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote: > > > Hey, > > > Since there currently is no cancel/stop facility in Form.Observer, your > > only shot is to use some variable accessible by your callback, that > > toggles it off after the first shot, e.g. > > > var formChanged = function() { > > if (arguments.callee.notAnymore) return; > > // ... > > arguments.callee.notAnymore = true;} > > > formChanged.prototype.notAnymore = false; > > > new Form.Observer(''formId'', 2, formChanged); > > > (yes, function prototypes can be used to store "function-static" > > variables... You''ll see this trick here and there in Prototype''s source > > code). > > > -- > > Christophe Porteneuve a.k.a. TDD > > "[They] did not know it was impossible, so they did it." --Mark Twain > > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---