Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show placeholder text in ruby on rails password field tags

In Ruby on Rails, I have the line

<td><%= text_field_tag(:email, "email") %></td>

which places the word "e-mail" in the box where e-mail is supposed to go. This is exactly what I want, as it saves space. However, when I do this:

<td><%= password_field_tag(:password, "password") %></td>

The text is just a bunch of dots. I want the text to say password, but when the user fills it in I want dots to appear. Facebook does exactly what I want here https://www.facebook.com.

Could someone please tell me how to accomplish writing the word "password" visibly in the password field box yet having the password appear dotted-out when the user actually goes to fill it in?

like image 243
dinosaurW Avatar asked Jan 29 '26 16:01

dinosaurW


1 Answers

You need to set the placeholder attribute, not the value attribute:

<td><%= password_field_tag(:password, "", placeholder: "Password") %></td>

You should do the same thing for your email field. Don't set the value of the element, set a placeholder and let the browser render it specifically as a placeholder.

The actual textual value of the password field will always render as dots or asterisks, regardless of whether you set it via script or the user types it.

like image 62
meagar Avatar answered Jan 31 '26 06:01

meagar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!