Module: Formtastic::Helpers::FormHelper
- Defined in:
- lib/formtastic/helpers/form_helper.rb
Overview
FormHelper provides a handful of wrappers around Rails' built-in form helpers methods to set
the :builder option to Formtastic::FormBuilder and apply some class names to the <form>
tag.
The following methods are wrapped:
semantic_form_fortoform_forsemantic_fields_fortofields_forsemantic_remote_form_forandsemantic_form_remote_fortoremote_form_for
The following two examples are effectively equivalent:
<%= form_for(@post, :builder => Formtastic::FormBuilder, :class => 'formtastic post') do |f| %>
#...
<% end %>
<%= semantic_form_for(@post) do |f| %>
#...
<% end %>
This simple wrapping means that all arguments, options and variations supported by Rails' own helpers are also supported by Formtastic.
Since Formtastic::FormBuilder subclasses Rails' own FormBuilder, you have access to all
of Rails' built-in form helper methods such as text_field, check_box, radio_button,
etc in addition to all of Formtastic's additional helpers like inputs,
input, buttons, etc:
<%= semantic_form_for(@post) do |f| %>
<!-- Formtastic -->
<%= f.input :title %>
<!-- Rails -->
<li class='something-custom'>
<%= f.label :title %>
<%= f.text_field :title %>
<p class='hints'>...</p>
</li>
<% end %>
Formtastic is a superset of Rails' FormBuilder. It deliberately avoids overriding or modifying the behavior of Rails' own form helpers so that you can use Formtastic helpers when suited, and fall back to regular Rails helpers, ERB and HTML when needed. In other words, you're never fully committed to The Formtastic Way.
Constant Summary collapse
- @@builder =
Allows the
:builderoption onform_foretc to be changed to your own which subclassesFormtastic::FormBuilder. Change this fromconfig/initializers/formtastic.rb. Formtastic::FormBuilder
- @@default_form_class =
Allows the default class we add to all
<form>tags to be changed fromformtastictowhatever. Change this fromconfig/initializers/formtastic.rb. 'formtastic'