Skip to content

Commit

Permalink
Extract SearchField
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 17, 2012
1 parent 675fb8d commit 4874716
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
15 changes: 1 addition & 14 deletions actionpack/lib/action_view/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -876,20 +876,7 @@ def radio_button(object_name, method, tag_value, options = {})
# # => <input autosave="com.example.www" id="user_name" incremental="true" name="user[name]" onsearch="true" results="10" size="30" type="search" />
#
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".
Expand Down
1 change: 1 addition & 0 deletions actionpack/lib/action_view/helpers/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Tags
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'
Expand Down
24 changes: 24 additions & 0 deletions actionpack/lib/action_view/helpers/tags/search_field.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4874716

Please sign in to comment.