简体   繁体   中英

Ruby On Rails: form_for label and text field

I have the following for:

<%= form_for Ggroup.new, url: what_to_do_files_path ,method: :get ,:validate => true do |f| %>
<div class="field_label">
<%= f.label :group_name%>
</div>
<div class="field">
<%=f.text_field :group_name %>
</div>
<%= button_tag :class => "btn btn-primary", :name => 'submit' do %> Submit <% end %>
lalala
<%end%>

So I have following structure: Group name the field for typing .
I would like to have the label inside the the field for typing. So that the words "Group name" would be not near the text field but inside it and the user will type his group name there. Thanks in advance.

Actually, the name of the functionality you are looking for is placeholder . You can implement a placeholder for textfield like this,

<%=f.text_field :group_name, placeholder: "Group Name" %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM