Hello dear Javascript Gurus, I have an issue with "overriding" event handlers. I know that Event.observe only adds event handlers. Lets say I have a form <form onsubmit="alert(''first'')" id="f1"> And I do not have influence on that -> this onsubmit handler inside the form API and cannot be changed. What I want to to is to register my own function on the submit Even.observe(''f1'',''submit'', function(evt) { Event.stop(evt); }) In this easy case I just want to prevent the submit. What happens is that first the alert (''first'') is executed. After that the event is stopped. What would be the best way to make sure my observe is called before the inline code (in this case nothing is alerted). For me it looks like the inline code is the first that is handled. Shall I, after adding my handlers, take the code from the inline, put it into an function, attach it as handler, and remove the inline submit code? Or any other best practices to deal with this? Thanks .: Fabian --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Best practice would be NOT to use inline handlers at all. Event.observe, on the other hand, does not guarantee order of events either, but you could always write a simple queue. --~--~---------~--~----~------------~-------~--~----~ 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 feared that this message will come, but perhaps I needed to make it more explicit, that I do not have control over inline event handlers :-) .: Fabian -----Original Message----- From: grbounce-_Pkz0AUAAAB9-VKt0-RY8LHUELm10l3Y=fabian.lange=web.de@googlegroups.c om [mailto:grbounce-_Pkz0AUAAAB9-VKt0-RY8LHUELm10l3Y=fabian.lange=web.de@google groups.com] On Behalf Of kangax Sent: Samstag, 22. Dezember 2007 21:33 To: Ruby on Rails: Spinoffs Subject: [Rails-spinoffs] Re: how to deal with inline defined event handlers Best practice would be NOT to use inline handlers at all. Event.observe, on the other hand, does not guarantee order of events either, but you could always write a simple queue. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 23, 6:33 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Best practice would be NOT to use inline handlers at all.It is far more efficient to use inline handlers than add them dynamically, I don''t think it is "best practice" to say they should never be used. -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Fabian, This is not tested, but perhaps you could overwrite the attribute? I know i can set the "inline" handler by setting the DOM reference.onclick property to a function. You could set it to Prototype.K and it would override the irritating alert function. Worth a try, let me know! Cheers On Dec 22, 10:15 pm, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On Dec 23, 6:33 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Best practice would be NOT to use inline handlers at all. > > It is far more efficient to use inline handlers than add them > dynamically, I don''t think it is "best practice" to say they should > never be used. > > -- > Rob--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---