Skip to content

Instantly share code, notes, and snippets.

@allaire
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allaire/0907dea15ddb081ad1a1 to your computer and use it in GitHub Desktop.
Save allaire/0907dea15ddb081ad1a1 to your computer and use it in GitHub Desktop.
Simple Form - Placeholders fallback on labels
# 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
@carlosantoniodasilva
Copy link

Nice 👍 ❤️

I think you should be able to refactor a little bit to avoid two roundtrips to i18n on the conditional:

translate_from_namespace(:placeholders).presence || translate_from_namespace(:labels)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment