开发者

Using autofocus and text_field form helpers in Rails

开发者 https://www.devze.com 2022-12-31 13:05 出处:网络
How do I include the \'autofocus\' attri开发者_C百科bute on an HTML5 form using the text_field form helper in Rails?

How do I include the 'autofocus' attri开发者_C百科bute on an HTML5 form using the text_field form helper in Rails?

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

Thanks


f.text_field :email, autofocus: true


This will work:

text_field_tag :reseller, '', autofocus: true

Note the empty value argument.


<%= 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;" %>

0

精彩评论

暂无评论...
验证码 换一张
取 消