aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorAlex Robbin <alex.robbin@meyouhealth.com>2014-08-22 09:54:54 -0400
committerAlex Robbin <alex.robbin@meyouhealth.com>2014-08-22 09:54:54 -0400
commitf99e62e2d9e010102788f1e728f54b03f65115c5 (patch)
treece685faa97a2b369c7c5e0a875fe93b9413fc784 /actionview
parentfea7fe1fd2c7dbd98cf8707f9ecd17d010777fc1 (diff)
downloadrails-f99e62e2d9e010102788f1e728f54b03f65115c5.tar.gz
rails-f99e62e2d9e010102788f1e728f54b03f65115c5.tar.bz2
rails-f99e62e2d9e010102788f1e728f54b03f65115c5.zip
just use the placeholder tag value if it is passed as a String
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/helpers/tags/placeholderable.rb4
-rw-r--r--actionview/test/template/form_helper_test.rb23
2 files changed, 22 insertions, 5 deletions
diff --git a/actionview/lib/action_view/helpers/tags/placeholderable.rb b/actionview/lib/action_view/helpers/tags/placeholderable.rb
index 313aa725c9..ae67bc13af 100644
--- a/actionview/lib/action_view/helpers/tags/placeholderable.rb
+++ b/actionview/lib/action_view/helpers/tags/placeholderable.rb
@@ -6,6 +6,8 @@ module ActionView
super
if tag_value = @options[:placeholder]
+ placeholder = tag_value if tag_value.is_a?(String)
+
object_name = @object_name.gsub(/\[(.*)_attributes\]\[\d+\]/, '.\1')
method_and_value = tag_value.is_a?(TrueClass) ? @method_name : "#{@method_name}.#{tag_value}"
@@ -15,7 +17,7 @@ module ActionView
end
i18n_default ||= ""
- placeholder = I18n.t("#{object_name}.#{method_and_value}", :default => i18n_default, :scope => "helpers.placeholder").presence
+ placeholder ||= I18n.t("#{object_name}.#{method_and_value}", :default => i18n_default, :scope => "helpers.placeholder").presence
placeholder ||= if object && object.class.respond_to?(:human_attribute_name)
object.class.human_attribute_name(method_and_value)
diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb
index d944214961..6910769183 100644
--- a/actionview/test/template/form_helper_test.rb
+++ b/actionview/test/template/form_helper_test.rb
@@ -344,15 +344,21 @@ class FormHelperTest < ActionView::TestCase
end
end
+ def test_text_field_placeholder_with_string_value
+ with_locale :placeholder do
+ assert_dom_equal('<input id="post_cost" name="post[cost]" placeholder="HOW MUCH?" type="text" />', text_field(:post, :cost, placeholder: "HOW MUCH?"))
+ end
+ end
+
def test_text_field_placeholder_with_human_attribute_name_and_value
with_locale :placeholder do
- assert_dom_equal('<input id="post_cost" name="post[cost]" placeholder="Pounds" type="text" />', text_field(:post, :cost, placeholder: "uk"))
+ assert_dom_equal('<input id="post_cost" name="post[cost]" placeholder="Pounds" type="text" />', text_field(:post, :cost, placeholder: :uk))
end
end
def test_text_field_placeholder_with_locales_and_value
with_locale :placeholder do
- assert_dom_equal('<input id="post_written_on" name="post[written_on]" placeholder="Escrito en" type="text" value="2004-06-15" />', text_field(:post, :written_on, placeholder: "spanish"))
+ assert_dom_equal('<input id="post_written_on" name="post[written_on]" placeholder="Escrito en" type="text" value="2004-06-15" />', text_field(:post, :written_on, placeholder: :spanish))
end
end
@@ -783,11 +789,20 @@ class FormHelperTest < ActionView::TestCase
end
end
+ def test_text_area_placeholder_with_string_value
+ with_locale :placeholder do
+ assert_dom_equal(
+ %{<textarea id="post_cost" name="post[cost]" placeholder="HOW MUCH?">\n</textarea>},
+ text_area(:post, :cost, placeholder: "HOW MUCH?")
+ )
+ end
+ end
+
def test_text_area_placeholder_with_human_attribute_name_and_value
with_locale :placeholder do
assert_dom_equal(
%{<textarea id="post_cost" name="post[cost]" placeholder="Pounds">\n</textarea>},
- text_area(:post, :cost, placeholder: "uk")
+ text_area(:post, :cost, placeholder: :uk)
)
end
end
@@ -796,7 +811,7 @@ class FormHelperTest < ActionView::TestCase
with_locale :placeholder do
assert_dom_equal(
%{<textarea id="post_written_on" name="post[written_on]" placeholder="Escrito en">\n2004-06-15</textarea>},
- text_area(:post, :written_on, placeholder: "spanish")
+ text_area(:post, :written_on, placeholder: :spanish)
)
end
end