Forum: Ruby on Rails RE: newbie q: Form element focus

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
337cdd270761e0e6f4356de45b04d388?d=identicon&s=25 Jonathan Viney (Guest)
on 2005-12-15 07:01
(Received via mailing list)
Using Prototype, just do Form.focusFirstElement(<form id here>);

For more Prototype help see:

http://www.sergiopereira.com/articles/prototype.js.html

Cheers, Jonathan.
1f1bd7de8337317975b0475be56392d2?d=identicon&s=25 Dan Tenenbaum (dandante)
on 2005-12-28 05:29
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.
8fd9f26b8f23d49c8a89b63f1279e24f?d=identicon&s=25 Chris Nolan.ca (Guest)
on 2005-12-28 09:57
(Received via mailing list)
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/
This topic is locked and can not be replied to.