set the input item class to "initialfocus" or something like that. put a function into your application.js which loops through form elements and sets the focus on the first (or last, or whatever) one it comes across w/ a class of "initialfocus". Attach this function to the window's load event.

No "initialfocus" option in the rails helpers... but you could add one easy enough that did the above. Probably wouldn't be necessary though. It's simple enough as is.

On Apr 30, 2007, at 2:48 PM, Glenn Little wrote:

I'm trying to set the initial focus to some specific form
field on a page.

I can use a prototype call to do something like:

<% form_tag .... %>
 <%= text_field_tag ... %>
 <script>$('text_field_id').focus();</script>
  <%= some_other_field_tag... %>

and it works, but I'm just wondering if there was a cleaner
way that I'm missing.  Ideally, I'd like not to have to
explicitly state the id of the input element.  Have I missed out
on an :initialfocus => true option to the form field helpers
or anything like that?

Thanks...

                -glenn
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to