Ensure type is text unless for url and email types.
This commit is contained in:
parent
e703b0ec26
commit
fcf06a5c76
|
@ -7,10 +7,14 @@ module SimpleForm
|
|||
|
||||
def input_html_options
|
||||
input_options = super
|
||||
input_options[:class] = "string #{input_options[:class]}" unless input_type == :string
|
||||
input_options[:size] ||= [limit, SimpleForm.default_input_size].compact.min
|
||||
input_options[:maxlength] ||= limit if limit
|
||||
input_options[:type] ||= input_type
|
||||
|
||||
unless input_type == :string
|
||||
input_options[:type] ||= input_type
|
||||
input_options[:class] = "string #{input_options[:class]}"
|
||||
end
|
||||
|
||||
input_options
|
||||
end
|
||||
|
||||
|
@ -21,4 +25,4 @@ module SimpleForm
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,22 +29,22 @@ class InputTest < ActionView::TestCase
|
|||
# TextFieldInput
|
||||
test 'input should map text field to string attribute' do
|
||||
with_input_for @user, :name, :string
|
||||
assert_select 'input[name=\'user[name]\'][id=user_name][value=New in Simple Form!]'
|
||||
assert_select 'input[name=\'user[name]\'][id=user_name][value=New in Simple Form!][type=text]'
|
||||
end
|
||||
|
||||
test 'input should generate an integer text field for integer attributes ' do
|
||||
with_input_for @user, :age, :integer
|
||||
assert_select 'input.integer#user_age'
|
||||
assert_select 'input[type=text].integer#user_age'
|
||||
end
|
||||
|
||||
test 'input should generate a float text field for float attributes ' do
|
||||
with_input_for @user, :age, :float
|
||||
assert_select 'input.float#user_age'
|
||||
assert_select 'input[type=text].float#user_age'
|
||||
end
|
||||
|
||||
test 'input should generate a decimal text field for decimal attributes ' do
|
||||
with_input_for @user, :age, :decimal
|
||||
assert_select 'input.decimal#user_age'
|
||||
assert_select 'input[type=text].decimal#user_age'
|
||||
end
|
||||
|
||||
test 'input should use default text size for decimal attributes' do
|
||||
|
|
|
@ -19,8 +19,8 @@ class Company < Struct.new(:id, :name)
|
|||
(a || {}).merge(b || {})
|
||||
end
|
||||
|
||||
def new_record?
|
||||
false
|
||||
def persisted?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -42,8 +42,8 @@ class User < OpenStruct
|
|||
@new_record = true
|
||||
end
|
||||
|
||||
def new_record?
|
||||
@new_record || false
|
||||
def persisted?
|
||||
!(@new_record || false)
|
||||
end
|
||||
|
||||
def company_attributes=(*)
|
||||
|
|
Loading…
Reference in New Issue