Lee
Lee

Reputation: 341

Using autofocus and text_field form helpers in Rails

How do I include the 'autofocus' attribute on an HTML5 form using the text_field form helper in Rails?

e.g. <%= f.text_field :email %> Where does autofocus go?

Thanks

Upvotes: 34

Views: 23117

Answers (3)

Pedro Rolo
Pedro Rolo

Reputation: 29970

f.text_field :email, autofocus: true

Upvotes: 64

przbadu
przbadu

Reputation: 6049

<%= f.text_field :email, nil, :autofocus => true %> will work.

similarly, if you want to use other HTML5 attributes and CSS classes, you can write :

<%= f.text_field :email, nil, :autofocus => true, :placeholder => "Your email Here", :class => "active", :style => "color: #333;" %>

Upvotes: 8

marcantonio
marcantonio

Reputation: 1069

This will work:

text_field_tag :reseller, '', autofocus: true

Note the empty value argument.

Upvotes: 12

Related Questions