Reputation: 341
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
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
Reputation: 1069
This will work:
text_field_tag :reseller, '', autofocus: true
Note the empty value
argument.
Upvotes: 12