Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

I18n support for HTML5 placeholder attribute

#6080

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

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

State: open
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Aditya Sanghi
    Aditya Sanghi
    • 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.

    November 29th, 2010 @ 10:45 AM

  2. Paul Schreiber
    Paul Schreiber
    • 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.

    December 7th, 2010 @ 06:45 AM

  3. rails
    rails
    • 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.

    March 8th, 2011 @ 12:00 AM

  4. rails
    rails
    • State changed from open to stale

    March 8th, 2011 @ 12:00 AM

  5. Paul Schreiber
    Paul Schreiber
    • 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]

    March 8th, 2011 @ 12:07 AM