mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
Allow passing default options to date, time and datetime select.
This commit is contained in:
parent
f441bbbf88
commit
d1796bc036
2 changed files with 40 additions and 4 deletions
|
@ -16,7 +16,7 @@ module SimpleForm
|
|||
return '' if @options[:label] == false
|
||||
unless label_text = @options[:label]
|
||||
default = @object.try(:human_attribute_name, @attribute.to_s) || @attribute.to_s.humanize
|
||||
label_text = I18n.t("views.labels.#{@object.class.name.underscore}.#{@attribute}", :default => default)
|
||||
label_text = I18n.t("views.labels.#{@object_name}.#{@attribute}", :default => default)
|
||||
end
|
||||
label(@attribute, label_text)
|
||||
end
|
||||
|
@ -25,6 +25,7 @@ module SimpleForm
|
|||
input_type = (@options[:as] || default_input_type).to_sym
|
||||
html_options = @options[:html] || {}
|
||||
html_options[:class] = "#{html_options[:class]} #{input_type}".strip
|
||||
@options[:options] ||= {}
|
||||
|
||||
input_field = case input_type
|
||||
when :boolean then
|
||||
|
@ -36,11 +37,11 @@ module SimpleForm
|
|||
when :text then
|
||||
text_area(@attribute, html_options)
|
||||
when :datetime then
|
||||
datetime_select(@attribute, options, html_options)
|
||||
datetime_select(@attribute, @options[:options], html_options)
|
||||
when :date then
|
||||
date_select(@attribute, options, html_options)
|
||||
date_select(@attribute, @options[:options], html_options)
|
||||
when :time then
|
||||
time_select(@attribute, options, html_options)
|
||||
time_select(@attribute, @options[:options], html_options)
|
||||
else
|
||||
text_field(@attribute, html_options)
|
||||
end
|
||||
|
|
|
@ -62,6 +62,18 @@ class InputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'input should be able to pass options to datetime select' do
|
||||
simple_form_for @user do |f|
|
||||
concat f.input :created_at, :options => {
|
||||
:disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
|
||||
}
|
||||
end
|
||||
assert_tag :tag => 'select', :attributes => { :disabled => 'disabled' }
|
||||
assert_select 'form select.datetime option', 'ano'
|
||||
assert_select 'form select.datetime option', 'mês'
|
||||
assert_select 'form select.datetime option', 'dia'
|
||||
end
|
||||
|
||||
test 'input should generate a date select by default for date attributes' do
|
||||
simple_form_for @user do |f|
|
||||
concat f.input :born_at
|
||||
|
@ -72,6 +84,18 @@ class InputTest < ActionView::TestCase
|
|||
assert_no_tag :tag => 'select', :attributes => { :id => "user_born_at_4i" }
|
||||
end
|
||||
|
||||
test 'input should be able to pass options to date select' do
|
||||
simple_form_for @user do |f|
|
||||
concat f.input :born_at, :options => {
|
||||
:disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
|
||||
}
|
||||
end
|
||||
assert_tag :tag => 'select', :attributes => { :disabled => 'disabled' }
|
||||
assert_select 'form select.date option', 'ano'
|
||||
assert_select 'form select.date option', 'mês'
|
||||
assert_select 'form select.date option', 'dia'
|
||||
end
|
||||
|
||||
test 'input should generate a time select by default for time attributes' do
|
||||
simple_form_for @user do |f|
|
||||
concat f.input :delivery_time
|
||||
|
@ -83,6 +107,17 @@ class InputTest < ActionView::TestCase
|
|||
assert_select "form select.time#user_delivery_time_5i"
|
||||
end
|
||||
|
||||
test 'input should be able to pass options to time select' do
|
||||
simple_form_for @user do |f|
|
||||
concat f.input :delivery_time, :options => {
|
||||
:disabled => true, :prompt => { :hour => 'hora', :minute => 'minuto' }
|
||||
}
|
||||
end
|
||||
assert_tag :tag => 'select', :attributes => { :disabled => 'disabled' }
|
||||
assert_select 'form select.time option', 'hora'
|
||||
assert_select 'form select.time option', 'minuto'
|
||||
end
|
||||
|
||||
test 'input should allow overwriting default type' do
|
||||
simple_form_for @user do |f|
|
||||
concat f.input :name, :as => :text
|
||||
|
|
Loading…
Reference in a new issue