Hi, all! First, thanks for the marvellous framework to the developers, it helped me a lot. But I have one problem. I''ve got an AJAX search on my page, which is executed by hitting Enter on a search textfield, so I need not to submit the form on this event. The code: <html> <head> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript"> Event.observe(window, ''load'', function() { $(''search'').observe(''keypress'', function(anEvent) { var which = anEvent.which || anEvent.keyCode; if (which == Event.KEY_RETURN) { alert(''You pushed Enter!''); // other stuff here Event.stop(anEvent); // doesn''t work in Opera } }); }); </script> </head> <body> <form> <input type="text" id="search" value=""> <input type="submit"> </form> </body> </html> It works ok in Firefox 2.0.0.4 and IE 6.0 (appears alert and form doesn''t submit), but Opera 9.21 ignores Event.stop(anEvent) and submits the form. Any ideas? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
conf, Remove the KEY_RETURN-handling code from your event handler and use something like this to prevent submit: $($(''search'').form).observe("submit", function(e) { Event.stop(e) }) If you have a more complex scenario in your form, you can inspect the event object on submit to see which form control it was triggered in and react accordingly. The rest is up to you. --~--~---------~--~----~------------~-------~--~----~ 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, I do recall having trouble with intercepting ''submit'' on forms submitted through the Return key with Opera. At the time, I actually had that same issue with Safari, although I believe it''s fixed by now. I *believe* it''s an Opera issue. Tobie, Mislav, etc. any idea? -- Christophe Porteneuve aka TDD 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 -~----------~----~----~----~------~----~------~--~---
On 28 июн, 15:35, Mislav <mislav.maroh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> conf, > > Remove the KEY_RETURN-handling code from your event handler and use > something like this to prevent submit: > > $($(''search'').form).observe("submit", function(e) { > Event.stop(e) > > })Mislav, thanks for the answer, but this solution doesn''t suit me, because I''ve got a lot of other fields that need to submit form on "enter".> If you have a more complex scenario in your form, you can inspect the > event object on submit to see which form control it was triggered in > and react accordingly. The rest is up to you.Exactly what I have. I''ve already solved my problem with other way (more simpler I think). It just surprised me why it works in IE and Firefox and doesn''t work in Opera. --~--~---------~--~----~------------~-------~--~----~ 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 stop the event as described in the thread above and then submit the form anyway as long as the submit conditions are met. In other words, your process would be this: 1. Stop the submission event. 2. Verify that form entries are valid. 3. If valid, submit the form. To submit a form, you just call the from''s submit() method like this. We''ll assume the form has an ID attribute of "searchForm:" $("searchForm").submit(); Or, since your submission event is fired from within the form from and form element, you could use the form property of the element which fired the event and make the function extensible to other forms: Event.element(event).form.submit(); - Dash - conf wrote:> On 28 июн, 15:35, Mislav <mislav.maroh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> conf, >> >> Remove the KEY_RETURN-handling code from your event handler and use >> something like this to prevent submit: >> >> $($(''search'').form).observe("submit", function(e) { >> Event.stop(e) >> >> }) >> > Mislav, thanks for the answer, but this solution doesn''t suit me, > because I''ve got a lot of other fields that need to submit form on > "enter". > >> If you have a more complex scenario in your form, you can inspect the >> event object on submit to see which form control it was triggered in >> and react accordingly. The rest is up to you. >> > Exactly what I have. I''ve already solved my problem with other way > (more simpler I think). > It just surprised me why it works in IE and Firefox and doesn''t work > in Opera. > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---