This is probably a dumb question, but is there an easy way to set the focus of a form to the first visible/editable element? I''ve been googling lots and searching documentation and haven''t come up with anything. Help would be appreciated. -- Posted via http://www.ruby-forum.com/.
In javascript assuming you have the prototype, etc libraries $(''form_element_id'').focus() On 12/14/05, Ryan Blanks <ryan.blanks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This is probably a dumb question, but is there an easy way to set the > focus of a form to the first visible/editable element? I''ve been > googling lots and searching documentation and haven''t come up with > anything. Help would be appreciated. > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Using Prototype, just do Form.focusFirstElement(<form id here>); For more Prototype help see: http://www.sergiopereira.com/articles/prototype.js.html Cheers, Jonathan. -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Blanks Sent: Thursday, 15 December 2005 12:03 p.m. To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] newbie q: Form element focus This is probably a dumb question, but is there an easy way to set the focus of a form to the first visible/editable element? I''ve been googling lots and searching documentation and haven''t come up with anything. Help would be appreciated. -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Someone asked how to set the focus on the first form element. Jonathan Viney answered:> Using Prototype, just do Form.focusFirstElement(<form id here>); > > For more Prototype help see: > > http://www.sergiopereira.com/articles/prototype.js.html > > Cheers, Jonathan.Thanks. However, I would like more detail. This javascript function takes as an argument the name of the form. I created my form using this line: <%= start_form_tag(:action => "createnewdocument") %> It shows up in HTML as follows: <form action="/document/createnewdocument" method="post"> So, two related questions: 1) How do I get start_form_tag() to generate a name for the form? 2) If I can''t do #1, what do I pass to the javascript function? What would be the exact code snippet? Thanks. -- Posted via http://www.ruby-forum.com/.
Dan, Take a look @ http://api.rubyonrails.com/classes/ActionView/Helpers/ FormTagHelper.html#M000403 which is the docs for the start_form_tag helper. It''s a bit confusing, but you can pass in the options as the second parameter, and the options are where you can set all the other html attributes. Instead of <%= start_form_tag(:action => "createnewdocument") %> do <%= start_form_tag( { :action => "createnewdocument") }, { :id => "MyFormName" } %> Note the {}''s around the :action, which is the ''url_for_options'' part of the helper. ''MyFormName'' is the id that you''d pass to the other function. Chris Nolan.ca http://kekova.ca/ On Dec 27, 2005, at 23:29, Dan Tenenbaum wrote:> > Thanks. However, I would like more detail. This javascript function > takes as an argument the name of the form. I created my form using > this > line: > <%= start_form_tag(:action => "createnewdocument") %> > > It shows up in HTML as follows: > <form action="/document/createnewdocument" method="post"> > > So, two related questions: > 1) How do I get start_form_tag() to generate a name for the form? > 2) If I can''t do #1, what do I pass to the javascript function? What > would be the exact code snippet?