Xavier Noria
2007-Apr-29 11:59 UTC
how to properly handle the return key on autocompletion
If the user presses the return key on an autocompletion list to select an item, the text field is updated just fine on Firefox and IE, but it also triggers form submit on Safari. You normally don''t want that submit. Looks like in Safari the srcElement of the onkeypress event is the text field itself, and see no way to distinguish the return in the completion list from a return in the text field (which is OK to submit the form). A possible workaround to this is to intercept the return key completely (and this prevent the user from submitting the form pressing return in the text field), is there a better solution? -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Peters
2007-Apr-29 23:56 UTC
Re: how to properly handle the return key on autocompletion
Xavier Noria wrote:> If the user presses the return key on an autocompletion list to > select an item, the text field is updated just fine on Firefox and > IE, but it also triggers form submit on Safari. You normally don''t > want that submit. Looks like in Safari the srcElement of the > onkeypress event is the text field itself, and see no way to > distinguish the return in the completion list from a return in the > text field (which is OK to submit the form).The behavior of the enter with regard to form submissions is not a standard. The different browsers try to behave in the same way, but they aren''t quite there.> A possible workaround to this is to intercept the return key > completely (and this prevent the user from submitting the form > pressing return in the text field), is there a better solution?I''ve found out that enter only submits the form if there is an input of type submit or image. So, you can change your submit into a button with an onclick handler. This will fix your problem but will also make it so that enter won''t submit the form for other fields either. To fix it for just that field you might have to change your local copy of scriptaculous to do something different with Safari. If you get it working, then definitely submit it back as a patch. -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Xavier Noria
2007-Apr-30 08:44 UTC
Re: how to properly handle the return key on autocompletion
On Apr 30, 2007, at 1:56 AM, Michael Peters wrote:> Xavier Noria wrote: >> If the user presses the return key on an autocompletion list to >> select an item, the text field is updated just fine on Firefox and >> IE, but it also triggers form submit on Safari. You normally don''t >> want that submit. Looks like in Safari the srcElement of the >> onkeypress event is the text field itself, and see no way to >> distinguish the return in the completion list from a return in the >> text field (which is OK to submit the form). > > The behavior of the enter with regard to form submissions is not a > standard. The > different browsers try to behave in the same way, but they aren''t > quite there. > >> A possible workaround to this is to intercept the return key >> completely (and this prevent the user from submitting the form >> pressing return in the text field), is there a better solution? > > I''ve found out that enter only submits the form if there is an > input of type > submit or image. So, you can change your submit into a button with > an onclick > handler. This will fix your problem but will also make it so that > enter won''t > submit the form for other fields either. > > To fix it for just that field you might have to change your local > copy of > scriptaculous to do something different with Safari. If you get it > working, then > definitely submit it back as a patch.This is in turn for a library that builds on top of the autocompeter [*], so I cannot assume much about the forms. By now I am disabling form submission altogether if :send_on_return is false. That prevents the issue in Safari but FF and IE have form submission disabled whereas it would work fine as is. I''ll think what to do. Thank you! -- fxn [*] http://agilewebdevelopment.com/plugins/model_auto_completer --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---