Friday, October 10, 2008

Auto Focusable Forms

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.

4 comments:

Anonymous said...

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.

Daniel Cadenas said...

Thanks for the patch! I think it's useful, I will add it to the plugin as soon as I have some free time.

Daniel Cadenas said...

Your change is pushed, thank you and sorry for the delay.

Daniel Cadenas said...

I wish I knew your name so I could at least add you in the commit info!