diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 462af7f2..588d966c 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -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 diff --git a/README.rdoc b/README.rdoc index e77560fe..fe8b4d39 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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 - diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index 1abd0c38..405bba55 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -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 diff --git a/test/form_builder_test.rb b/test/form_builder_test.rb index d8968608..8864e8da 100644 --- a/test/form_builder_test.rb +++ b/test/form_builder_test.rb @@ -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' diff --git a/test/inputs_test.rb b/test/inputs_test.rb index 1ad2bc40..1a578d30 100644 --- a/test/inputs_test.rb +++ b/test/inputs_test.rb @@ -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 diff --git a/test/support/models.rb b/test/support/models.rb index b6df5bd7..b11c324d 100644 --- a/test/support/models.rb +++ b/test/support/models.rb @@ -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|