Move 'input_method' to Base, map 'text_field' and 'password_field' in 'StringInput'

This commit is contained in:
Alexander Zubkov 2011-03-02 12:32:10 +03:00 committed by Rafael Mendonça França
parent 7121f3f2b6
commit cb1c8ffa57
3 changed files with 11 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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