From 487471611b8eab1f1367fa2ef93aed77fb52dee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 16 Jan 2012 21:25:32 -0300 Subject: Extract SearchField --- actionpack/lib/action_view/helpers/form_helper.rb | 15 +------------- actionpack/lib/action_view/helpers/tags.rb | 1 + .../lib/action_view/helpers/tags/search_field.rb | 24 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 actionpack/lib/action_view/helpers/tags/search_field.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 3b15e7097a..4348d36def 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -876,20 +876,7 @@ module ActionView # # => # def search_field(object_name, method, options = {}) - options = options.stringify_keys - - if options["autosave"] - if options["autosave"] == true - options["autosave"] = request.host.split(".").reverse.join(".") - end - options["results"] ||= 10 - end - - if options["onsearch"] - options["incremental"] = true unless options.has_key?("incremental") - end - - InstanceTag.new(object_name, method, self, options.delete("object")).to_input_field_tag("search", options) + ActionView::Helpers::Tags::SearchField.new(object_name, method, self, options).render end # Returns a text_field of type "tel". diff --git a/actionpack/lib/action_view/helpers/tags.rb b/actionpack/lib/action_view/helpers/tags.rb index 0ae7baffc6..a60d263cae 100644 --- a/actionpack/lib/action_view/helpers/tags.rb +++ b/actionpack/lib/action_view/helpers/tags.rb @@ -7,6 +7,7 @@ module ActionView autoload :PasswordField, 'action_view/helpers/tags/password_field' autoload :HiddenField, 'action_view/helpers/tags/hidden_field' autoload :FileField, 'action_view/helpers/tags/file_field' + autoload :SearchField, 'action_view/helpers/tags/search_field' autoload :TextArea, 'action_view/helpers/tags/text_area' autoload :CheckBox, 'action_view/helpers/tags/check_box' autoload :RadioButton, 'action_view/helpers/tags/radio_button' diff --git a/actionpack/lib/action_view/helpers/tags/search_field.rb b/actionpack/lib/action_view/helpers/tags/search_field.rb new file mode 100644 index 0000000000..818fd4b887 --- /dev/null +++ b/actionpack/lib/action_view/helpers/tags/search_field.rb @@ -0,0 +1,24 @@ +module ActionView + module Helpers + module Tags + class SearchField < TextField #:nodoc: + def render + options = @options.stringify_keys + + if options["autosave"] + if options["autosave"] == true + options["autosave"] = request.host.split(".").reverse.join(".") + end + options["results"] ||= 10 + end + + if options["onsearch"] + options["incremental"] = true unless options.has_key?("incremental") + end + + super + end + end + end + end +end -- cgit v1.2.3