This project is archived and is in readonly mode.

#6080 open
Paul Schreiber

I18n support for HTML5 placeholder attribute

Reported by Paul Schreiber | November 28th, 2010 @ 10:47 PM

Currently, Rails' I18n system automatically looks up localized text for <label> tags. It would be nice if it did something similar for the HTML5 placeholder attribute.

Your en.yml file would like this:

helpers:
 placeholder:
  person:
   first_name: "John"
   last_name: "Doe"

Your ERB would look the same:
<%= f.text_field :first_name %>

Your HTML would look like this:
<input id="person_first_name" name="person[first_name]" placeholder="John" type="text" />

Currently, you have to clutter up your markup like so:
<%= f.text_field :first_name, :placeholder => t('helpers.placeholder.person.first_name') %>

Comments and changes to this ticket

  • Aditya Sanghi

    Aditya Sanghi November 29th, 2010 @ 10:45 AM

    • Tag set to actionview, html5
    • Importance changed from “” to “Low”

    Please feel free to submit a patch as per the http://rails.lighthouseapp.com/projects/8994/sending-patches .

    I however suggest you first start a discussion about this feature on the Rails mailing list since you are proposing for rails to always add a placeholder if an entry in the locale exists for an attribute.

    I think it's better for user to explicitly state if they want a placeholder for a particular field. Perhaps :placeholder => true would be a better way to trigger an i18n lookup if a string is not provided with the attribute.

  • Paul Schreiber

    Paul Schreiber December 7th, 2010 @ 06:45 AM

    • Tag changed from actionview, html5 to actionview, html5, patch

    I posted this to the Rails mailing list:
    http://groups.google.com/group/rubyonrails-talk/browse_thread/threa...

    The attached patch modifies to_input_field_tag to perform an I18n lookup if no :placeholder option is supplied.

  • rails

    rails March 8th, 2011 @ 12:00 AM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails March 8th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”
  • Paul Schreiber

    Paul Schreiber March 8th, 2011 @ 12:07 AM

    • State changed from “stale” to “open”

    This is still an issue in 3.0.5. I've already provided a patch. Can someone please review this? [state:open]

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages