1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

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

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

View file

@ -48,6 +48,20 @@ class InputTest < ActionView::TestCase
assert_select 'input.string[size=50]' assert_select 'input.string[size=50]'
end 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 # NumericInput
test 'input should generate an integer text field for integer attributes ' do test 'input should generate an integer text field for integer attributes ' do
with_input_for @user, :age, :integer with_input_for @user, :age, :integer