简体   繁体   中英

Adding a Placeholder on a Form Rails 4

I need to add a Placeholder on a form that I am writing. I tried the following, and some other variations without success:

<%= form_tag("/search", method: "get") do %>
    <%= label_tag(:address, "Address:", placeholder: '100 Brooklyn Ave Unit 3' ) %>
    <%= text_field_tag(:address) %>
    <%= label_tag(:citystatezip, "City and State OR ZIP:", placeholder: 'New York, NY') %>
    <%= text_field_tag(:citystatezip) %>
    <%= submit_tag("Enter Address") %>
  <% end %>

You don't put placeholders in label tags, they should be placed in input fields, text_field_tag in this case:

<%= form_tag("/search", method: "get") do %>
  <%= label_tag(:address, "Address:") %>
  <%= text_field_tag(:address, nil, placeholder: '100 Brooklyn Ave Unit 3') %>
  <%= label_tag(:citystatezip, "City and State OR ZIP:") %>
  <%= text_field_tag(:citystatezip, nil, placeholder: 'New York, NY') %>
  <%= submit_tag("Enter Address") %>
<% end %>

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