I use auto-complete to help with tag entry and a few other areas. Some example code is: <label for="f_r_tags">Tags (ex: "sales compliance", marketing, fast)</ label><br/> <%= form.text_field :tag_list, :maxlength => 255, :id => ''f_r_tags'', :autocomplete => ''off'' %> <%= ajax_spinner_for(''f_r_tags'') %> <%= content_tag(''div'', '''', :class => ''auto_complete'', :id => ''f_r_tags_auto_complete'') %> <%= auto_complete_field(''f_r_tags'', :url => autocomplete_tags_requests_path, :method => :get, :frequency => 0.5, :indicator => ''f_r_tags_spinner'', :tokens => '','') %> Everything works great, but how do I prevent ENTER from submitting the form. When people use this, they usually start typing, see the tag they want, use the arrow keys to select the tag, then hit enter to select it. However, rather than do what is expected, the form gets submitted. It drives the user nuts. I want enter to submit the form only when not selecting a tag from the auto-complete list. Is this possible? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
After some more digging, it seems like I''m not the only one seeing this: http://dev.rubyonrails.org/ticket/2600. On Jan 27, 2:13 pm, gobigdave <gobigd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I use auto-complete to help with tag entry and a few other areas. Some > example code is: > > <label for="f_r_tags">Tags (ex: "sales compliance", marketing, fast)</ > label><br/> > <%= form.text_field :tag_list, :maxlength => 255, :id => > ''f_r_tags'', :autocomplete => ''off'' %> > <%= ajax_spinner_for(''f_r_tags'') %> > <%= content_tag(''div'', '''', :class => ''auto_complete'', :id => > ''f_r_tags_auto_complete'') %> > <%= auto_complete_field(''f_r_tags'', :url => > autocomplete_tags_requests_path, :method => :get, :frequency => > 0.5, :indicator => ''f_r_tags_spinner'', :tokens => '','') %> > > Everything works great, but how do I prevent ENTER from submitting the > form. When people use this, they usually start typing, see the tag > they want, use the arrow keys to select the tag, then hit enter to > select it. However, rather than do what is expected, the form gets > submitted. It drives the user nuts. > > I want enter to submit the form only when not selecting a tag from the > auto-complete list. Is this possible?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 27, 2008, at 8:13 PM, gobigdave wrote:> I use auto-complete to help with tag entry and a few other areas. Some > example code is: > > <label for="f_r_tags">Tags (ex: "sales compliance", marketing, fast)</ > label><br/> > <%= form.text_field :tag_list, :maxlength => 255, :id => > ''f_r_tags'', :autocomplete => ''off'' %> > <%= ajax_spinner_for(''f_r_tags'') %> > <%= content_tag(''div'', '''', :class => ''auto_complete'', :id => > ''f_r_tags_auto_complete'') %> > <%= auto_complete_field(''f_r_tags'', :url => > autocomplete_tags_requests_path, :method => :get, :frequency => > 0.5, :indicator => ''f_r_tags_spinner'', :tokens => '','') %> > > Everything works great, but how do I prevent ENTER from submitting the > form. When people use this, they usually start typing, see the tag > they want, use the arrow keys to select the tag, then hit enter to > select it. However, rather than do what is expected, the form gets > submitted. It drives the user nuts. > > I want enter to submit the form only when not selecting a tag from the > auto-complete list. Is this possible?Yes, you can prevent form submission capturing the return key. To do that include something like this in tag_options: # starting point, needs more work to be portable :onkeypress => "return event.which == Event.KEY_RETURN ? false : true" -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Which element do I add :onkeypress to? Also, this problem looks to be limited to FF 2 on OSX. Enter does not submit the form on Safari 3, WinFF2, or IE7. On Jan 27, 3:04 pm, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Jan 27, 2008, at 8:13 PM, gobigdave wrote: > > > > > I use auto-complete to help with tag entry and a few other areas. Some > > example code is: > > > <label for="f_r_tags">Tags (ex: "sales compliance", marketing, fast)</ > > label><br/> > > <%= form.text_field :tag_list, :maxlength => 255, :id => > > ''f_r_tags'', :autocomplete => ''off'' %> > > <%= ajax_spinner_for(''f_r_tags'') %> > > <%= content_tag(''div'', '''', :class => ''auto_complete'', :id => > > ''f_r_tags_auto_complete'') %> > > <%= auto_complete_field(''f_r_tags'', :url => > > autocomplete_tags_requests_path, :method => :get, :frequency => > > 0.5, :indicator => ''f_r_tags_spinner'', :tokens => '','') %> > > > Everything works great, but how do I prevent ENTER from submitting the > > form. When people use this, they usually start typing, see the tag > > they want, use the arrow keys to select the tag, then hit enter to > > select it. However, rather than do what is expected, the form gets > > submitted. It drives the user nuts. > > > I want enter to submit the form only when not selecting a tag from the > > auto-complete list. Is this possible? > > Yes, you can prevent form submission capturing the return key. To do > that include something like this in tag_options: > > # starting point, needs more work to be portable > :onkeypress => "return event.which == Event.KEY_RETURN ? false : > true" > > -- fxn--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 27, 2008, at 9:24 PM, gobigdave wrote:> Which element do I add :onkeypress to?The option goes in the hash that is the 3rd argument of text_field_with_auto_complete.> Also, this problem looks to be limited to FF 2 on OSX. Enter does not > submit the form on Safari 3, WinFF2, or IE7.Yes, I am no JavaScript expert but experience says that particular issue is a bit brittle. I don''t like disabling the return key that way indeed. I''d prefer to let the user select with the keyboard using the return key in the completion list, and still be able to send the form if he''s in the very text field. I have not found a way to accomplish that in a robust and portable way. -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---