How can I add placeholder
text to my f.text_field
fields so that the text comes pre-written by default, and when a user click inside the fields, the text goes away - allowing the user to type in the new text?
标签:
ruby-on-rails
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
- Rails how to handle error and exceptions in model
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
In your view template, set a default value:
In your Javascript (assuming jquery here):
For those using Rails(4.2) Internationalization (I18n):
Set the placeholder attribute to true:
and in your local file (ie. en.yml):
Here is a much cleaner syntax if using
rails 4+
So
rails 4+
can now use this syntax instead of the hash syntaxIn Rails 4(Using HAML):
With rails >= 3.0, you can simply use the
placeholder
option.I tried the solutions above and it looks like on rails 5.* the second agument by default is the value of the input form, what worked for me was: