Add :search and :tel input types
:tel is automatically mapped from attributes matching "phone".
This commit is contained in:
parent
66555b1e60
commit
6764fc6ee1
|
@ -5,6 +5,7 @@
|
|||
* collection_check_boxes and collection_radio now wrap the input in the label
|
||||
* Automatic add min/max values for numeric attributes based on validations and step for integers - HTML5 (by github.com/dasch)
|
||||
* Add :placeholder option for string inputs, allowing customization through I18n - HTML5 (by github.com/jonathan)
|
||||
* Add :search and :tel input types, with :tel mapping automatically from attributes matching "phone" - HTML5
|
||||
|
||||
* bug fix
|
||||
* Search for validations on both association and attribute
|
||||
|
|
|
@ -237,7 +237,9 @@ SimpleForm comes with a lot of default mappings:
|
|||
string text field string
|
||||
email email field string with name matching "email"
|
||||
url url field string with name matching "url"
|
||||
tel tel field string with name matching "phone"
|
||||
password password field string with name matching "password"
|
||||
search search -
|
||||
text text area text
|
||||
file file field string, responding to file methods
|
||||
hidden hidden field -
|
||||
|
|
|
@ -6,13 +6,13 @@ module SimpleForm
|
|||
extend MapType
|
||||
include SimpleForm::Inputs
|
||||
|
||||
map_type :password, :text, :file, :to => SimpleForm::Inputs::MappingInput
|
||||
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 :date, :time, :datetime, :to => SimpleForm::Inputs::DateTimeInput
|
||||
map_type :country, :time_zone, :to => SimpleForm::Inputs::PriorityInput
|
||||
map_type :boolean, :to => SimpleForm::Inputs::BooleanInput
|
||||
map_type :password, :text, :file, :to => SimpleForm::Inputs::MappingInput
|
||||
map_type :string, :email, :search, :tel, :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 :date, :time, :datetime, :to => SimpleForm::Inputs::DateTimeInput
|
||||
map_type :country, :time_zone, :to => SimpleForm::Inputs::PriorityInput
|
||||
map_type :boolean, :to => SimpleForm::Inputs::BooleanInput
|
||||
|
||||
# Basic input helper, combines all components in the stack to generate
|
||||
# input html based on options the user define and some guesses through
|
||||
|
@ -262,6 +262,7 @@ module SimpleForm
|
|||
when /time_zone/ then :time_zone
|
||||
when /country/ then :country
|
||||
when /email/ then :email
|
||||
when /phone/ then :tel
|
||||
when /url/ then :url
|
||||
end
|
||||
|
||||
|
|
|
@ -108,6 +108,11 @@ class FormBuilderTest < ActionView::TestCase
|
|||
assert_select 'form input#user_email.string.email'
|
||||
end
|
||||
|
||||
test 'builder should generate tel fields for columns that matches phone' do
|
||||
with_form_for @user, :phone_number
|
||||
assert_select 'form input#user_phone_number.string.tel'
|
||||
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'
|
||||
|
|
|
@ -67,6 +67,13 @@ class InputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
[:email, :url, :search, :tel].each do |type|
|
||||
test "input should allow type #{type}" do
|
||||
with_input_for @user, :name, type
|
||||
assert_select "input.string.#{type}"
|
||||
end
|
||||
end
|
||||
|
||||
# NumericInput
|
||||
test 'input should generate an integer text field for integer attributes ' do
|
||||
with_input_for @user, :age, :integer
|
||||
|
|
|
@ -40,7 +40,7 @@ class User
|
|||
|
||||
attr_accessor :id, :name, :company, :company_id, :time_zone, :active, :description, :created_at, :updated_at,
|
||||
:credit_limit, :age, :password, :delivery_time, :born_at, :special_company_id, :country, :url, :tag_ids,
|
||||
:avatar, :email, :status, :residence_country
|
||||
:avatar, :email, :status, :residence_country, :phone_number
|
||||
|
||||
def initialize(options={})
|
||||
options.each do |key, value|
|
||||
|
|
Loading…
Reference in New Issue