Plugins - Auto Focusable Forms

StarAdd to favorites

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

Daniel Cadenas

http://github.com/dcadenas/auto_focusable_forms

git://github.com/dcadenas/auto_focusable_forms.git

Rails' (MIT)

  • Currently 4.8/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

View Extensions

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?