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
|
private
|
||||||
|
|
||||||
def label_target
|
def label_target
|
||||||
position = case input_type
|
if use_html5_inputs?
|
||||||
when :date, :datetime
|
attribute_name
|
||||||
date_order = input_options[:order] || I18n.t('date.order')
|
|
||||||
date_order.first.to_sym
|
|
||||||
else
|
else
|
||||||
:hour
|
position = case input_type
|
||||||
end
|
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]
|
position = ActionView::Helpers::DateTimeSelector::POSITION[position]
|
||||||
"#{attribute_name}_#{position}i"
|
"#{attribute_name}_#{position}i"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def use_html5_inputs?
|
def use_html5_inputs?
|
||||||
|
|
|
@ -169,4 +169,9 @@ class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
||||||
with_input_for :project, :created_at, :time, html5: false
|
with_input_for :project, :created_at, :time, html5: false
|
||||||
assert_select 'label[for=project_created_at_4i]'
|
assert_select 'label[for=project_created_at_4i]'
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue