Adding a placeholder option to the string input and have it use

i18n translation, when possible.
This commit is contained in:
Jonathan Hicks 2010-09-23 02:45:22 +08:00 committed by Carlos Antonio da Silva
parent 348b327e00
commit 22d05e65ab
3 changed files with 23 additions and 4 deletions

View File

@ -18,4 +18,4 @@ module SimpleForm
end
end
end
end
end

View File

@ -7,9 +7,10 @@ module SimpleForm
def input_html_options
input_options = super
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[: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 if placeholder
input_options
end
@ -22,6 +23,10 @@ module SimpleForm
def limit
column && column.limit
end
def placeholder
@placeholder ||= options[:placeholder] || translate(:placeholder)
end
end
end
end

View File

@ -48,6 +48,20 @@ class InputTest < ActionView::TestCase
assert_select 'input.string[size=50]'
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]'
end
test 'input should use i18n to translate placeholder text' do
store_translations(:en, :simple_form => { :placeholder => { :user => {
:name => 'Name goes here'
} } }) do
with_input_for @user, :name, :string
assert_select 'input.string[placeholder=Name goes here]'
end
end
# NumericInput
test 'input should generate an integer text field for integer attributes ' do
with_input_for @user, :age, :integer