Permalink
Browse files

Extract PasswordField

  • Loading branch information...
1 parent 514308a commit 0ac47bd8192cb8b5b61b6a9ab2ce8b3b352870f7 @rafaelfranca rafaelfranca committed Jan 16, 2012
@@ -699,7 +699,7 @@ def text_field(object_name, method, options = {})
# # => <input type="password" id="account_pin" name="account[pin]" size="20" class="form_input" />
#
def password_field(object_name, method, options = {})
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("password", { :value => nil }.merge!(options))
+ ActionView::Helpers::Tags::PasswordField.new(object_name, method, self, options).render
end
# Returns a hidden input tag tailored for accessing a specified attribute (identified by +method+) on an object
@@ -1,9 +1,10 @@
module ActionView
module Helpers
module Tags
- autoload :Base, 'action_view/helpers/tags/base'
- autoload :Label, 'action_view/helpers/tags/label'
- autoload :TextField, 'action_view/helpers/tags/text_field'
+ autoload :Base, 'action_view/helpers/tags/base'
+ autoload :Label, 'action_view/helpers/tags/label'
+ autoload :TextField, 'action_view/helpers/tags/text_field'
+ autoload :PasswordField, 'action_view/helpers/tags/password_field'
end
end
end
@@ -0,0 +1,12 @@
+module ActionView
+ module Helpers
+ module Tags
+ class PasswordField < TextField #:nodoc:
+ def render
+ @options = {:value => nil}.merge!(@options)
+ super
+ end
+ end
+ end
+ end
+end
@@ -6,12 +6,18 @@ def render
options = @options.stringify_keys
options["size"] = options["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless options.key?("size")
options = DEFAULT_FIELD_OPTIONS.merge(options)
- options["type"] ||= "text"
+ options["type"] ||= field_type
options["value"] = options.fetch("value"){ value_before_type_cast(object) }
options["value"] &&= ERB::Util.html_escape(options["value"])
add_default_name_and_id(options)
tag("input", options)
end
+
+ private
+
+ def field_type
+ self.class.name.split("::").last.sub("Field", "").downcase
+ end
end
end
end

0 comments on commit 0ac47bd

Please sign in to comment.