maudulus
maudulus

Reputation: 11045

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 %>

Upvotes: 0

Views: 86

Answers (1)

vee
vee

Reputation: 38645

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 %>

Upvotes: 1

Related Questions