Just commited a Rails plugin (my first one, yay!!) to give automatic focus to the first input of the first form in each of your views.
Of course you can disable this behaviour but I think that having focus in the first input by default can be very useful.
You can read more in the project page here.
5 comments:
Hi,
If a field already has a value, the current code puts the cursor at the beginning of the field. I patched line 25 of lib/autofocusable.rb to look like this:
@template.instance_variable_set('@focus_was_set', @template.javascript_tag("document.getElementById('#{tag_id(method_name)}').focus();\n document.getElementById('#{tag_id(method_name)}').value = document.getElementById('#{tag_id(method_name)}').value;"))
It is a cross-browser trick to make sure the cursor gets set at the end of the text field.
Thanks for the patch! I think it's useful, I will add it to the plugin as soon as I have some free time.
Your change is pushed, thank you and sorry for the delay.
I wish I knew your name so I could at least add you in the commit info!
Hola Daniel. Soy un nuevo desarrollador de argentina y queria implementar este interesante aporte tuyo a los formularios.
No me queda claro como hacerlo en los siguientes puntos:
1. Definir un campo para que automaticamente tome foco al iniciar el form.
2. Establecer una secuencia en los focos de los demás campos.
Podés ayudarme ?
Saludos, Fabian
Post a Comment