Reputation: 165
I would like to add username inside the username text field in my application (vs having a label next to it) the user would be able to type over this text. I've seen it done in html but I'm confused as to how to do it on my new.html.erb page since im using the form_for tag and the text_field tag.
thanks in advanced!
Upvotes: 0
Views: 1590
Reputation: 19031
Use "placeholder".
<%= form_for @user do |f| %>
<%= f.text_field :username, :placeholder => "Username" %>
...
<%= f.submit %>
<% end %>
This will only work for html5 supported browsers by the way, so make sure you have jquery fallback for IE 8, 7 etc.
Upvotes: 1
Reputation: 12399
This is achieved by using the HTML5 placeholder attribute.
In rails, you can simply add the placeholder attribute:
<%= f.text_field :whatever, :placeholder => "text for placeholder..." %>
Upvotes: 0