How do I make DOM elements available to my script after an Ajax.Updater? So for example I have this in my JS Event.observe(''signinForm'', ''submit'', checkForm); Now let''s say signinForm does not exist yet. It exists after an Ajax.Updater. How do I make my script aware that it is available now? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
One of the options is to use an Ajax.Updater callback [1] to attach observers once content is inserted into the DOM ... onComplete: function() { ... Event.observe(''signinForm'', ''submit'', checkForm); } ... [1] http://www.prototypejs.org/api/ajax/options - kangax On Apr 18, 4:21 pm, anathema <spamfreeunive...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How do I make DOM elements available to my script after an > Ajax.Updater? So for example I have this in my JS > > Event.observe(''signinForm'', ''submit'', checkForm); > > Now let''s say signinForm does not exist yet. It exists after an > Ajax.Updater. How do I make my script aware that it is available now?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I sort of knew that was going to be the response. I should have mentioned it. The problem I see with that is, what if i have a bunch of stuff to observe? The code would become cluttered fast because I would be repeating myself everywhere. I need to come up with something that is reusable in multiple onCompletes and observes for multiple ID''s. On Apr 18, 2:04 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> One of the options is to use an Ajax.Updater callback [1] to attach > observers once content is inserted into the DOM > ... > onComplete: function() { > ... > Event.observe(''signinForm'', ''submit'', checkForm); > } > ... > > [1]http://www.prototypejs.org/api/ajax/options > > - kangax > > On Apr 18, 4:21 pm, anathema <spamfreeunive...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > How do I make DOM elements available to my script after an > > Ajax.Updater? So for example I have this in my JS > > > Event.observe(''signinForm'', ''submit'', checkForm); > > > Now let''s say signinForm does not exist yet. It exists after an > > Ajax.Updater. How do I make my script aware that it is available now?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Event delegation should do it: document.observe(''submit'', function(e) { if (e.target.hasClassName(''validation-required'')) { if (!validateForm(e.target)) e.stop(); } }); - kangax On Apr 18, 5:31 pm, anathema <spamfreeunive...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I sort of knew that was going to be the response. I should have > mentioned it. > > The problem I see with that is, what if i have a bunch of stuff to > observe? The code would become cluttered fast because I would be > repeating myself everywhere. I need to come up with something that is > reusable in multiple onCompletes and observes for multiple ID''s. > > On Apr 18, 2:04 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > One of the options is to use an Ajax.Updater callback [1] to attach > > observers once content is inserted into the DOM > > ... > > onComplete: function() { > > ... > > Event.observe(''signinForm'', ''submit'', checkForm); > > } > > ... > > > [1]http://www.prototypejs.org/api/ajax/options > > > - kangax > > > On Apr 18, 4:21 pm, anathema <spamfreeunive...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > How do I make DOM elements available to my script after an > > > Ajax.Updater? So for example I have this in my JS > > > > Event.observe(''signinForm'', ''submit'', checkForm); > > > > Now let''s say signinForm does not exist yet. It exists after an > > > Ajax.Updater. How do I make my script aware that it is available now?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---