instance method search_field

Ruby on Rails 3.2.22.5

Since v3.0.20

Available in: v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

search_field(object_name, method, options = {})

Returns an input of type “search” for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object_name). Inputs of type “search” may be styled differently by some browsers.

Examples

search_field(:user, :name)
# => <input id="user_name" name="user[name]" size="30" type="search" />
search_field(:user, :name, :autosave => false)
# => <input autosave="false" id="user_name" name="user[name]" size="30" type="search" />
search_field(:user, :name, :results => 3)
# => <input id="user_name" name="user[name]" results="3" size="30" type="search" />
#  Assume request.host returns "www.example.com"
search_field(:user, :name, :autosave => true)
# => <input autosave="com.example.www" id="user_name" name="user[name]" results="10" size="30" type="search" />
search_field(:user, :name, :onsearch => true)
# => <input id="user_name" incremental="true" name="user[name]" onsearch="true" size="30" type="search" />
search_field(:user, :name, :autosave => false, :onsearch => true)
# => <input autosave="false" id="user_name" incremental="true" name="user[name]" onsearch="true" size="30" type="search" />
search_field(:user, :name, :autosave => true, :onsearch => true)
# => <input autosave="com.example.www" id="user_name" incremental="true" name="user[name]" onsearch="true" results="10" size="30" type="search" />

Parameters

object_name req
method req
options opt = {}
Source
# File actionpack/lib/action_view/helpers/form_helper.rb, line 888
      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)
      end

Defined in actionpack/lib/action_view/helpers/form_helper.rb line 888 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::Helpers::FormHelper

Type at least 2 characters to search.

↑↓ navigate · open · esc close