Add support for both email and url input types from HTML 5.
This commit is contained in:
parent
086b20a7a5
commit
433f5a7603
|
@ -0,0 +1,8 @@
|
||||||
|
== 1.1
|
||||||
|
|
||||||
|
* enhancements
|
||||||
|
* Rails 3 support with generators, templates and HTML 5
|
||||||
|
|
||||||
|
== 1.0
|
||||||
|
|
||||||
|
* First release
|
|
@ -7,7 +7,8 @@ module SimpleForm
|
||||||
include SimpleForm::Inputs
|
include SimpleForm::Inputs
|
||||||
|
|
||||||
map_type :boolean, :password, :text, :file, :to => SimpleForm::Inputs::MappingInput
|
map_type :boolean, :password, :text, :file, :to => SimpleForm::Inputs::MappingInput
|
||||||
map_type :string, :integer, :decimal, :float, :to => SimpleForm::Inputs::TextFieldInput
|
map_type :string, :email, :url, :to => SimpleForm::Inputs::StringInput
|
||||||
|
map_type :integer, :decimal, :float, :to => SimpleForm::Inputs::NumericInput
|
||||||
map_type :select, :radio, :check_boxes, :to => SimpleForm::Inputs::CollectionInput
|
map_type :select, :radio, :check_boxes, :to => SimpleForm::Inputs::CollectionInput
|
||||||
map_type :date, :time, :datetime, :to => SimpleForm::Inputs::DateTimeInput
|
map_type :date, :time, :datetime, :to => SimpleForm::Inputs::DateTimeInput
|
||||||
map_type :country, :time_zone, :to => SimpleForm::Inputs::PriorityInput
|
map_type :country, :time_zone, :to => SimpleForm::Inputs::PriorityInput
|
||||||
|
@ -270,6 +271,8 @@ module SimpleForm
|
||||||
when /password/ then :password
|
when /password/ then :password
|
||||||
when /time_zone/ then :time_zone
|
when /time_zone/ then :time_zone
|
||||||
when /country/ then :country
|
when /country/ then :country
|
||||||
|
when /email/ then :email
|
||||||
|
when /url/ then :url
|
||||||
end
|
end
|
||||||
|
|
||||||
match || input_type || file_method? || :string
|
match || input_type || file_method? || :string
|
||||||
|
|
|
@ -6,7 +6,8 @@ module SimpleForm
|
||||||
autoload :DateTimeInput, 'simple_form/inputs/date_time_input'
|
autoload :DateTimeInput, 'simple_form/inputs/date_time_input'
|
||||||
autoload :HiddenInput, 'simple_form/inputs/hidden_input'
|
autoload :HiddenInput, 'simple_form/inputs/hidden_input'
|
||||||
autoload :MappingInput, 'simple_form/inputs/mapping_input'
|
autoload :MappingInput, 'simple_form/inputs/mapping_input'
|
||||||
|
autoload :NumericInput, 'simple_form/inputs/numeric_input'
|
||||||
autoload :PriorityInput, 'simple_form/inputs/priority_input'
|
autoload :PriorityInput, 'simple_form/inputs/priority_input'
|
||||||
autoload :TextFieldInput, 'simple_form/inputs/text_field_input'
|
autoload :StringInput, 'simple_form/inputs/string_input'
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
module SimpleForm
|
||||||
|
module Inputs
|
||||||
|
class NumericInput < Base
|
||||||
|
def input
|
||||||
|
@builder.text_field(attribute_name, input_html_options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def input_html_options
|
||||||
|
input_options = super
|
||||||
|
input_options[:class] = "numeric #{input_options[:class]}"
|
||||||
|
input_options[:size] ||= SimpleForm.default_input_size
|
||||||
|
input_options
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,24 @@
|
||||||
|
module SimpleForm
|
||||||
|
module Inputs
|
||||||
|
class StringInput < Base
|
||||||
|
def input
|
||||||
|
@builder.text_field(attribute_name, input_html_options)
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
input_options
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def limit
|
||||||
|
column && column.limit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,27 +0,0 @@
|
||||||
module SimpleForm
|
|
||||||
module Inputs
|
|
||||||
# Handles common text field inputs, as String, Numeric, Float and Decimal.
|
|
||||||
class TextFieldInput < Base
|
|
||||||
def input
|
|
||||||
@builder.text_field(attribute_name, input_html_options)
|
|
||||||
end
|
|
||||||
|
|
||||||
def input_html_options
|
|
||||||
input_options = super
|
|
||||||
if text_type? && column && column.limit
|
|
||||||
input_options[:size] ||= [column.limit, SimpleForm.default_input_size].min
|
|
||||||
input_options[:maxlength] ||= column.limit
|
|
||||||
else
|
|
||||||
input_options[:size] ||= SimpleForm.default_input_size
|
|
||||||
end
|
|
||||||
input_options
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def text_type?
|
|
||||||
[:string, :email, :url].include?(input_type)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -79,12 +79,12 @@ class FormBuilderTest < ActionView::TestCase
|
||||||
|
|
||||||
test 'builder should use integer text field for integer columns' do
|
test 'builder should use integer text field for integer columns' do
|
||||||
with_form_for @user, :age
|
with_form_for @user, :age
|
||||||
assert_select 'form input#user_age.integer'
|
assert_select 'form input#user_age.numeric.integer'
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'builder should generate decimal text field for decimal columns' do
|
test 'builder should generate decimal text field for decimal columns' do
|
||||||
with_form_for @user, :credit_limit
|
with_form_for @user, :credit_limit
|
||||||
assert_select 'form input#user_credit_limit.decimal'
|
assert_select 'form input#user_credit_limit.numeric.decimal'
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'builder should generate password fields for columns that matches password' do
|
test 'builder should generate password fields for columns that matches password' do
|
||||||
|
@ -102,6 +102,16 @@ class FormBuilderTest < ActionView::TestCase
|
||||||
assert_select 'form select#user_time_zone.time_zone'
|
assert_select 'form select#user_time_zone.time_zone'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'builder should generate email fields for columns that matches email' do
|
||||||
|
with_form_for @user, :email
|
||||||
|
assert_select 'form input#user_email.string.email'
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'builder should generate url fields for columns that matches url' do
|
||||||
|
with_form_for @user, :url
|
||||||
|
assert_select 'form input#user_url.string.url'
|
||||||
|
end
|
||||||
|
|
||||||
test 'builder should generate date select for date columns' do
|
test 'builder should generate date select for date columns' do
|
||||||
with_form_for @user, :born_at
|
with_form_for @user, :born_at
|
||||||
assert_select 'form select#user_born_at_1i.date'
|
assert_select 'form select#user_born_at_1i.date'
|
||||||
|
|
Loading…
Reference in New Issue