Do not pass :include_blank for DateTime inputs neither for PriorityZones when a priority is defined.
This commit is contained in:
parent
371c8cd2fd
commit
3873728e03
|
@ -26,7 +26,6 @@ module SimpleForm
|
|||
end
|
||||
|
||||
def input_options
|
||||
options[:include_blank] = true unless skip_include_blank?
|
||||
options
|
||||
end
|
||||
|
||||
|
@ -58,11 +57,6 @@ module SimpleForm
|
|||
reflection ? reflection.name : attribute_name
|
||||
end
|
||||
|
||||
# Check if :include_blank must be included by default.
|
||||
def skip_include_blank?
|
||||
options.key?(:prompt) || options.key?(:include_blank)
|
||||
end
|
||||
|
||||
# Retrieve options for the given namespace from the options hash
|
||||
def html_options_for(namespace, *extra)
|
||||
html_options = options[:"#{namespace}_html"] || {}
|
||||
|
|
|
@ -19,10 +19,18 @@ module SimpleForm
|
|||
options[:label_method], input_options, input_html_options)
|
||||
end
|
||||
|
||||
def input_options
|
||||
options = super
|
||||
options[:include_blank] = true unless skip_include_blank?
|
||||
options
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Check if :include_blank must be included by default.
|
||||
def skip_include_blank?
|
||||
super || options[:input_html].try(:[], :multiple)
|
||||
(options.keys & [:prompt, :include_blank, :default, :selected]).any? ||
|
||||
options[:input_html].try(:[], :multiple)
|
||||
end
|
||||
|
||||
# Detect the right method to find the label and value for a collection.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module SimpleForm
|
||||
module Inputs
|
||||
class PriorityInput < Base
|
||||
class PriorityInput < CollectionInput
|
||||
def input
|
||||
@builder.send(:"#{input_type}_select", attribute_name, input_priority,
|
||||
input_options, input_html_options)
|
||||
|
@ -9,6 +9,12 @@ module SimpleForm
|
|||
def input_priority
|
||||
options[:priority] || SimpleForm.send(:"#{input_type}_priority")
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def skip_include_blank?
|
||||
super || input_priority.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -120,11 +120,13 @@ class InputTest < ActionView::TestCase
|
|||
test 'input should generate a time zone select field with default' do
|
||||
with_input_for @user, :time_zone, :time_zone, :default => 'Brasilia'
|
||||
assert_select 'select option[value=Brasilia][selected=selected]'
|
||||
assert_no_select 'select option[value=]'
|
||||
end
|
||||
|
||||
test 'input should generate a time zone select using options priority' do
|
||||
with_input_for @user, :time_zone, :time_zone, :priority => /Brasilia/
|
||||
assert_select 'select option[value=][disabled=disabled]'
|
||||
assert_no_select 'select option[value=]', /^$/
|
||||
end
|
||||
|
||||
# DateTime input
|
||||
|
@ -163,6 +165,11 @@ class InputTest < ActionView::TestCase
|
|||
assert_select 'select.date option', 'dia'
|
||||
end
|
||||
|
||||
test 'input should be able to pass :default to date select' do
|
||||
with_input_for @user, :born_at, :date, :default => Date.today
|
||||
assert_select "select.date option[value=#{Date.today.year}][selected=selected]"
|
||||
end
|
||||
|
||||
test 'input should generate a time select for time attributes' do
|
||||
with_input_for @user, :delivery_time, :time
|
||||
assert_select 'input[type=hidden]#user_delivery_time_1i'
|
||||
|
|
Loading…
Reference in New Issue