Last active
August 29, 2015 14:05
-
-
Save allaire/0907dea15ddb081ad1a1 to your computer and use it in GitHub Desktop.
Simple Form - Placeholders fallback on labels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monkeypatch placeholders to use labels as a fallback instead | |
module SimpleForm | |
module Components | |
module Placeholders | |
def placeholder_text | |
placeholder = options[:placeholder] | |
placeholder.is_a?(String) ? placeholder : (translate_from_namespace(:placeholders).present? ? translate_from_namespace(:placeholders) : translate_from_namespace(:labels)) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice 👍 ❤️
I think you should be able to refactor a little bit to avoid two roundtrips to i18n on the conditional: