How do I set focus on a specific form field when I render a partial from the controller? I can do it with page[''name''].focus from an RJS view, but I can''t figure out how to do it when rendering this rhtml partial from the controller. I''m rendering a partial with two fields and neither one has focus until I hit the tab key or put the cursor in a field with the mouse. Sure would appreciate a pointer ! Thanks in advance, Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060426/6a7a2ae3/attachment-0001.html
How do I set focus on a specific form field when I render a partial from the controller? I can do it with page[''name''].focus from an RJS view, but I can''t figure out how to do it when rendering this rhtml partial from the controller. I''m rendering a partial with two fields and neither one has focus until I hit the tab key or put the cursor in a field with the mouse. Sure would appreciate a pointer ! Thanks in advance, Bill _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
tabindex HTML attribute? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> How do I set focus on a specific form field when I render a partial from > the controller? > > I can do it with page[''name''].focus from an RJS view, but I can''t figure > out how to do it when rendering this rhtml partial from the controller. > > I''m rendering a partial with two fields and neither one has focus until > I hit the tab key or put the cursor in a field with the mouse. Sure > would appreciate a pointer ! > > Thanks in advance, > BillSimple javascript should do it. _my_partial.rhtml <%= text_field ''foo'', ''bar'' %> <%= javascript_tag "$(''foo_bar'').focus" %> <!-- or --> <%= javascript_tag render(:update) { |page| page[''foo_bar''].focus } %> The browser will execute any <script> tags when its inserted via ajax. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---