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
Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in _tag (such as text_field_tag and check_box_tag ), generate just a single <input> element. The first parameter to these is always the name of the input.
This is the name used to generate the input's name (and the params' names), example: = form_for Admin.new, as: :user do |f| #^^^^ = f.input :username # will generate an input like this: <input type='text' name='user[username]' #... /> #
f.text_field :email, autofocus: true
This will work:
text_field_tag :reseller, '', autofocus: true
Note the empty value
argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With