Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using autofocus and text_field form helpers in Rails

Tags:

html

forms

ruby

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

like image 777
Lee Avatar asked May 19 '10 14:05

Lee


People also ask

What is form helper in Rails?

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.

What is Form_for in Ruby?

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]' #... /> #


2 Answers

f.text_field :email, autofocus: true

like image 169
Pedro Rolo Avatar answered Sep 17 '22 17:09

Pedro Rolo


This will work:

text_field_tag :reseller, '', autofocus: true 

Note the empty value argument.

like image 35
marcantonio Avatar answered Sep 20 '22 17:09

marcantonio