Agile Web Development

Build it. Launch it. Love it.

Auto Focusable Forms

Example:

If you have this two forms in your view…

  form_for @user do |f|
    f.text_field :name
    f.text_field :surname
    fields_for @post do |g|
      g.text_field :title
      g.text_area :content
    end
  end

  form_for @post do |f|
    f.text_field :title
  end

…you’ll see that the name field will have focus.

If you want to disable this behaviour just add :autofocus => false and the form will have the original Rails behaviour. So if for example you want to give focus to the second form in your view you’d just disable autofocus in the first form:

  form_for @user, :autofocus => false do |f|
    f.text_field :name
    f.text_field :surname
  end

  form_for @post do |f|
    f.text_field :title
    f.text_field :content
  end

And now the focus will be in the title field.

See the specs for more examples

Install:

    $ sudo ruby script/plugin install git://github.com/dcadenas/auto_focusable_forms.git

Vitals

Home http://github.com/dcadenas/auto_focusable_forms
Repository git://github.com/dcadenas/auto_focusable_forms.git
License Rails' (MIT)
Tags Tag_red focus forms
Rating (6 votes)
Owner Daniel Cadenas
Created 12 October 2008

Comments

Add a comment