diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 00e93e19..103520f3 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -189,6 +189,11 @@ module SimpleForm action = action.to_sym ACTIONS[action] || action end + + def input_method + self.class.mappings[input_type] or + raise("Could not find method for #{input_type.inspect}") + end end end end diff --git a/lib/simple_form/inputs/mapping_input.rb b/lib/simple_form/inputs/mapping_input.rb index 16c57eff..14a1faee 100644 --- a/lib/simple_form/inputs/mapping_input.rb +++ b/lib/simple_form/inputs/mapping_input.rb @@ -13,11 +13,6 @@ module SimpleForm private - def input_method - self.class.mappings[input_type] or - raise("Could not find method for #{input_type.inspect}") - end - def has_placeholder? (text? || password?) && placeholder_present? end diff --git a/lib/simple_form/inputs/string_input.rb b/lib/simple_form/inputs/string_input.rb index ac4be8ec..1ed030b5 100644 --- a/lib/simple_form/inputs/string_input.rb +++ b/lib/simple_form/inputs/string_input.rb @@ -1,12 +1,17 @@ module SimpleForm module Inputs class StringInput < Base + extend MapType + + map_type :string, :email, :search, :tel, :url, :to => :text_field + map_type :password, :to => :password_field + def input input_html_options[:size] ||= [limit, SimpleForm.default_input_size].compact.min input_html_options[:maxlength] ||= limit if limit input_html_options[:type] ||= input_type unless string? - @builder.text_field(attribute_name, input_html_options) + @builder.send(input_method, attribute_name, input_html_options) end def input_html_classes