I have successfully implemented my first Ruby on Rails application!
Now, my users are of course wanting piddly little things like:
** Pressing “enter” to save the form - currently when they press
enter it does not save and moves away from the form causing them to
have to re-enter data.
** Having the cursor default to the first field in the form when the
form opens.
Where is a good place to find out how to do little things like this?
As always, any advice or suggestion is welcome and appreciated!
** Pressing “enter” to save the form - currently when they press
enter it does not save and moves away from the form causing them to
have to re-enter data.
Odd… that should just happen by default…
** Having the cursor default to the first field in the form when the
form opens.
Let’s say your form has the attribute name=‘myform’ then you could do
something like this (after your form ends):
Thanks so much for the reply. I tried the code you suggested and the
form just does not want to set focus. I tried those sites you sent as
well, and tried changing the code to:
Thanks so much for the reply. I tried the code you suggested and the
form just does not want to set focus. I tried those sites you sent as
well, and tried changing the code to:
I have the line of code in my _form at the end. Any other suggestions?
Thanks again!! ~Ali
Try
document.forms[0].elements[0].focus();
for the first form element of the first form on the page.
Or, if you want to focus on a particular named input field:
$(‘user_name’).focus();
This requires protoype.js.
BTW, this has nothing to do with Rails or Ruby. This is really basic
javascript stuff - there are plenty of really good resources and
tutorials out there.
Cheers,
–max
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.