Hello, Perhaps I''m missing something here, but if I set an event (say on a link) which returns false. Event.observe(link, ''click'', function() { ...; return false;}) That false value doesn''t seem to be used and my click is triggering the action of following the href for the associated link. How do I get the observe to actually use the returned function value and not trigger the action? Or do I have to manually chain the events if I want to make use of the return value? Thanks, Andrew --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick a écrit :> Hello, > > Perhaps I''m missing something here, but if I set an event (say on a > link) which returns false. > > Event.observe(link, ''click'', function() { ...; return false;}) > > That false value doesn''t seem to be used and my click is triggering > the action of following the href for the associated link.That''s simply because the "return false" thing is not quite portable, and also because your function''s return value is, anyway, not used by the event handler. The CLEAN, PORTABLE way to cancel the default action is to use this in your function: Event.observe(link, ''click'', function(e) { Event.stop(e); // your code here. }); Prototype smooths over the differences between W3C''s DOM Level 2 Events and Microsoft''s fully proprietary handling. It ensures your function gets passed the event. The Event.stop method does two things, actually: * It prevents the default action from occurring (W3C: event.preventDefault(). IE: event.returnValue = false) * It stops event propagation/bubbling (W3C: event.stopPropagation(). IE: event.cancelBubble = true) That''s the best way to go that I know of... -- 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 -~----------~----~----~----~------~----~------~--~---
Thanks, was just replying with the same solution (found via some more googling and looking at prototype code). I have it working now. Thanks again. On 12/6/06, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> > Andrew Kaspick a écrit : > > Hello, > > > > Perhaps I''m missing something here, but if I set an event (say on a > > link) which returns false. > > > > Event.observe(link, ''click'', function() { ...; return false;}) > > > > That false value doesn''t seem to be used and my click is triggering > > the action of following the href for the associated link. > > That''s simply because the "return false" thing is not quite portable, > and also because your function''s return value is, anyway, not used by > the event handler. > > The CLEAN, PORTABLE way to cancel the default action is to use this in > your function: > > Event.observe(link, ''click'', function(e) { > Event.stop(e); > // your code here. > }); > > Prototype smooths over the differences between W3C''s DOM Level 2 Events > and Microsoft''s fully proprietary handling. It ensures your function > gets passed the event. The Event.stop method does two things, actually: > > * It prevents the default action from occurring > (W3C: event.preventDefault(). IE: event.returnValue = false) > * It stops event propagation/bubbling > (W3C: event.stopPropagation(). IE: event.cancelBubble = true) > > That''s the best way to go that I know of... > > -- > 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 -~----------~----~----~----~------~----~------~--~---