Module: Hanami::Helpers::FormHelper

Defined in:
gems/gems/hanami-helpers-1.3.1/lib/hanami/helpers/form_helper.rb,
gems/gems/hanami-helpers-1.3.1/lib/hanami/helpers/form_helper/values.rb,
gems/gems/hanami-helpers-1.3.1/lib/hanami/helpers/form_helper/html_node.rb,
gems/gems/hanami-helpers-1.3.1/lib/hanami/helpers/form_helper/form_builder.rb,
gems/gems/hanami-helpers-1.3.2/lib/hanami/helpers/form_helper.rb,
gems/gems/hanami-helpers-1.3.2/lib/hanami/helpers/form_helper/values.rb,
gems/gems/hanami-helpers-1.3.2/lib/hanami/helpers/form_helper/html_node.rb,
gems/gems/hanami-helpers-1.3.2/lib/hanami/helpers/form_helper/form_builder.rb

Overview

Form builder

By including Hanami::Helpers::FormHelper it will inject one public method: form_for. This is a HTML5 form builder.

To understand the general HTML5 builder syntax of this framework, please consider to have a look at Hanami::Helpers::HtmlHelper documentation.

This builder is independent from any template engine. This was hard to achieve without a compromise: the form helper should be used in one output block in a template or as a method in a view (see the examples below).

Features:

  • Support for complex markup without the need of concatenation

  • Auto closing HTML5 tags

  • Support for view local variables

  • Method override support (PUT/PATCH/DELETE HTTP verbs aren't understood by browsers)

  • Automatic generation of HTML attributes for inputs: id, name, value

  • Allow to override HTML attributes

  • Extract values from request params and fill value attributes

  • Automatic selection of current value for radio button and select inputs

  • Infinite nested fields

Supported tags and inputs:

  • check_box

  • color_field

  • date_field

  • datetime_field

  • datetime_local_field

  • email_field

  • fields_for

  • file_field

  • form_for

  • hidden_field

  • label

  • number_field

  • password_field

  • radio_button

  • select

  • submit

  • text_area

  • text_field

Examples:

One output block (template)

<%=
  form_for :book, routes.books_path do
    text_field :title

    submit 'Create'
  end
%>

Method (view)

require 'hanami/helpers'

class MyView
  include Hanami::Helpers::FormHelper

  def my_form
    form_for :book, routes.books_path do
      text_field :title
    end
  end
end

<!-- use this in the template -->
<%= my_form %>

See Also:

Since:

  • 0.2.0