# -*- coding: utf-8 -*- module Formtastic module Helpers # {#input} is used to render all content (labels, form widgets, error messages, hints, etc) for # a single form input (or field), usually representing a single method or attribute on the # form's object or model. # # The content is wrapped in an `
  • ` tag, so it's usually called inside an {Formtastic::Helpers::InputsHelper#inputs inputs} block # (which renders an `
      ` inside a `
      `), which should be inside a {Formtastic::Helpers::FormHelper#semantic_form_for `semantic_form_for`} # block: # # <%= semantic_form_for @post do |f| %> # <%= f.inputs do %> # <%= f.input :title %> # <%= f.input :body %> # <% end %> # <% end %> # # The HTML output will be something like: # #
      #
      #
        #
      1. # ... #
      2. #
      3. # ... #
      4. #
      #
      #
      # # @see #input # @see Formtastic::Helpers::InputsHelper#inputs # @see Formtastic::Helpers::FormHelper#semantic_form_for module InputHelper INPUT_CLASS_DEPRECATION = 'configure Formtastic::FormBuilder.input_class_finder instead'.freeze private_constant(:INPUT_CLASS_DEPRECATION) include Formtastic::Helpers::Reflection include Formtastic::Helpers::FileColumnDetection # Returns a chunk of HTML markup for a given `method` on the form object, wrapped in # an `
    1. ` wrapper tag with appropriate `class` and `id` attribute hooks for CSS and JS. # In many cases, the contents of the wrapper will be as simple as a `
    2. # # #
    3. # # In other cases (like a series of checkboxes for a `has_many` relationship), the wrapper may # include more complex markup, like a nested `
      ` with a `` and an `
        ` of # checkbox/label pairs for each choice: # # <%= f.input :categories, :as => :check_boxes, :collection => Category.active.ordered %> # #
      1. #
        # Categories #
          #
        1. # #
        2. #
        3. # #
        4. #
        5. # #
        6. #
        #
        #
      2. # # Sensible defaults for all options are guessed by looking at the method name, database column # information, association information, validation information, etc. For example, a `:string` # database column will map to a `:string` input, but if the method name contains 'email', will # map to an `:email` input instead. `belongs_to` associations will have a `:select` input, etc. # # Formtastic supports many different styles of inputs, and you can/should override the default # with the `:as` option. Internally, the symbol is used to map to a protected method # responsible for the details. For example, `:as => :string` will map to `string_input`, # defined in a module of the same name. Detailed documentation for each input style and it's # supported options is available on the `*_input` method in each module (links provided below). # # Available input styles: # # * `:boolean` (see {Inputs::BooleanInput}) # * `:check_boxes` (see {Inputs::CheckBoxesInput}) # * `:color` (see {Inputs::ColorInput}) # * `:country` (see {Inputs::CountryInput}) # * `:datetime_select` (see {Inputs::DatetimeSelectInput}) # * `:date_select` (see {Inputs::DateSelectInput}) # * `:email` (see {Inputs::EmailInput}) # * `:file` (see {Inputs::FileInput}) # * `:hidden` (see {Inputs::HiddenInput}) # * `:number` (see {Inputs::NumberInput}) # * `:password` (see {Inputs::PasswordInput}) # * `:phone` (see {Inputs::PhoneInput}) # * `:radio` (see {Inputs::RadioInput}) # * `:search` (see {Inputs::SearchInput}) # * `:select` (see {Inputs::SelectInput}) # * `:string` (see {Inputs::StringInput}) # * `:text` (see {Inputs::TextInput}) # * `:time_zone` (see {Inputs::TimeZoneInput}) # * `:time_select` (see {Inputs::TimeSelectInput}) # * `:url` (see {Inputs::UrlInput}) # # Calling `:as => :string` (for example) will call `#to_html` on a new instance of # `Formtastic::Inputs::StringInput`. Before this, Formtastic will try to instantiate a top-level # namespace StringInput, meaning you can subclass and modify `Formtastic::Inputs::StringInput` # in `app/inputs/`. This also means you can create your own new input types in `app/inputs/`. # # @todo document the "guessing" of input style # # @param [Symbol] method # The database column or method name on the form object that this input represents # # @option options :as [Symbol] # Override the style of input should be rendered # # @option options :label [String, Symbol, false] # Override the label text # # @option options :hint [String, Symbol, false] # Override hint text # # @option options :required [Boolean] # Override to mark the input as required (or not) — adds a required/optional class to the wrapper, and a HTML5 required attribute to the `` # # @option options :input_html [Hash] # Override or add to the HTML attributes to be passed down to the `` tag # # @option options :wrapper_html [Hash] # Override or add to the HTML attributes to be passed down to the wrapping `
      3. ` tag # # @option options :collection [Array, Hash{String => String, Boolean}, OrderedHash{String => String, Boolean}] # Override collection of objects in the association (`:select`, `:radio` & `:check_boxes` inputs only) # # @option options :member_label [Symbol, Proc, Method] # Override the method called on each object in the `:collection` for use as the `