Ensure placeholders are not generated with blank values

This commit is contained in:
Carlos Antonio da Silva 2010-09-24 00:44:13 -03:00
parent 85922612fc
commit 6a7841d9e3
3 changed files with 11 additions and 2 deletions

View File

@ -10,7 +10,7 @@ module SimpleForm
input_options[:size] ||= [limit, SimpleForm.default_input_size].compact.min
input_options[:maxlength] ||= limit if limit
input_options[:type] ||= input_type unless input_type == :string
input_options[:placeholder] ||= placeholder unless options[:placeholder] == false
input_options[:placeholder] ||= placeholder if has_placeholder?
input_options
end
@ -24,6 +24,10 @@ module SimpleForm
column && column.limit
end
def has_placeholder?
options[:placeholder] != false && placeholder.present?
end
def placeholder
@placeholder ||= options[:placeholder] || translate(:placeholder)
end

View File

@ -235,7 +235,7 @@ class FormBuilderTest < ActionView::TestCase
:name => 'Name goes here'
} } }) do
with_form_for @user, :name, :placeholder => false
assert_no_select 'input.string[placeholder=Name goes here]'
assert_no_select 'input[placeholder]'
end
end

View File

@ -48,6 +48,11 @@ class InputTest < ActionView::TestCase
assert_select 'input.string[size=50]'
end
test 'input should not generate placeholder by default' do
with_input_for @user, :name, :string
assert_no_select 'input[placeholder]'
end
test 'input should accept the placeholder option' do
with_input_for @user, :name, :string, :placeholder => 'Put in some text'
assert_select 'input.string[placeholder=Put in some text]'