From df7f3455a1f850649ad7d4c0c37ccab178717956 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 23 Feb 2005 00:50:34 +0000 Subject: Added FormHelper#file_field and FormTagHelper#file_field_tag for creating file upload fields git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@750 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/form_helper.rb | 7 ++++++- actionpack/lib/action_view/helpers/form_tag_helper.rb | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 36e1f946f8..b5a4403f76 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -78,6 +78,11 @@ module ActionView InstanceTag.new(object, method, self).to_input_field_tag("hidden", options) end + # Works just like text_field, but returns a input tag of the "file" type instead, which won't have any default value. + def file_field(object, method, options = {}) + InstanceTag.new(object, method, self).to_input_field_tag("file", options) + end + # Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by +method+) # on an object assigned to the template (identified by +object+). Additional options on the input tag can be passed as a # hash with +options+. @@ -147,7 +152,7 @@ module ActionView html_options.merge!({ "size" => options["maxlength"]}) if options["maxlength"] && !options["size"] html_options.delete("size") if field_type == "hidden" html_options.merge!({ "type" => field_type}) - html_options.merge!({ "value" => value_before_type_cast }) unless options["value"] + html_options.merge!({ "value" => value_before_type_cast }) if options["value"].nil? || field_type == "file" add_default_name_and_id(html_options) tag("input", html_options) end diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 78123a9d87..a5b18fe7f0 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -43,6 +43,10 @@ module ActionView text_field_tag(name, value, options.update("type" => "hidden")) end + def file_field_tag(name, options = {}) + text_field_tag(name, nil, options.update("type" => "file")) + end + def password_field_tag(name = "password", value = nil, options = {}) text_field_tag(name, value, options.update("type" => "password")) end -- cgit v1.2.3