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

Fix label for datetime inputs, point to first select

Point the label for datetime inputs at the first select. The date order can be
overridden by i18n and on a per-input basis. Use the specified order to
discover the first select.
This commit is contained in:
George Hemmings 2012-02-04 13:56:39 +00:00
parent 10bd50dcf8
commit 151b0d8fb9
3 changed files with 25 additions and 7 deletions

View file

@ -14,7 +14,10 @@ module SimpleForm
def label_target def label_target
case input_type case input_type
when :date, :datetime when :date, :datetime
"#{attribute_name}_1i" date_order = input_options[:order] || I18n.t('date.order')
type = date_order.first
position = ActionView::Helpers::DateTimeSelector::POSITION[type]
"#{attribute_name}_#{position}i"
when :time when :time
"#{attribute_name}_4i" "#{attribute_name}_4i"
end end

View file

@ -62,14 +62,28 @@ class DateTimeInputTest < ActionView::TestCase
assert_select 'select.time option', 'minuto' assert_select 'select.time option', 'minuto'
end end
test 'label should point to first option when date input type' do test 'label should use i18n to get target for date input type' do
with_input_for :project, :created_at, :date store_translations(:en, :date => { :order => [:month, :day, :year] }) do
assert_select 'label[for=project_created_at_1i]' with_input_for :project, :created_at, :date
assert_select 'label[for=project_created_at_2i]'
end
end end
test 'label should point to first option when datetime input type' do test 'label should use i18n to get target for datetime input type' do
with_input_for :project, :created_at, :datetime store_translations(:en, :date => { :order => [:month, :day, :year] }) do
assert_select 'label[for=project_created_at_1i]' with_input_for :project, :created_at, :datetime
assert_select 'label[for=project_created_at_2i]'
end
end
test 'label should use order to get target when date input type' do
with_input_for :project, :created_at, :date, :order => [:month, :year, :day]
assert_select 'label[for=project_created_at_2i]'
end
test 'label should use order to get target when datetime input type' do
with_input_for :project, :created_at, :datetime, :order => [:month, :year, :day]
assert_select 'label[for=project_created_at_2i]'
end end
test 'label should point to first option when time input type' do test 'label should point to first option when time input type' do

View file

@ -5,6 +5,7 @@ module MiscHelpers
yield yield
ensure ensure
I18n.reload! I18n.reload!
I18n.backend.send :init_translations
end end
end end