mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
Merge pull request #1183 from ericsullivan/fix_html5_date_label
fix label on dates if HTML5 compatibility is explicitly enbled
This commit is contained in:
commit
4c633a1b7c
2 changed files with 17 additions and 8 deletions
|
@ -14,16 +14,20 @@ module SimpleForm
|
|||
private
|
||||
|
||||
def label_target
|
||||
position = case input_type
|
||||
when :date, :datetime
|
||||
date_order = input_options[:order] || I18n.t('date.order')
|
||||
date_order.first.to_sym
|
||||
if use_html5_inputs?
|
||||
attribute_name
|
||||
else
|
||||
:hour
|
||||
end
|
||||
position = case input_type
|
||||
when :date, :datetime
|
||||
date_order = input_options[:order] || I18n.t('date.order')
|
||||
date_order.first.to_sym
|
||||
else
|
||||
:hour
|
||||
end
|
||||
|
||||
position = ActionView::Helpers::DateTimeSelector::POSITION[position]
|
||||
"#{attribute_name}_#{position}i"
|
||||
position = ActionView::Helpers::DateTimeSelector::POSITION[position]
|
||||
"#{attribute_name}_#{position}i"
|
||||
end
|
||||
end
|
||||
|
||||
def use_html5_inputs?
|
||||
|
|
|
@ -169,4 +169,9 @@ class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
|||
with_input_for :project, :created_at, :time, html5: false
|
||||
assert_select 'label[for=project_created_at_4i]'
|
||||
end
|
||||
|
||||
test 'label points to attribute_name if HTML5 compatibility is explicitly enbled' do
|
||||
with_input_for :project, :created_at, :date, html5: true
|
||||
assert_select 'label[for=project_created_at]'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue