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:
parent
348b327e00
commit
22d05e65ab
3 changed files with 23 additions and 4 deletions
|
@ -10,6 +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 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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue