Module: Formtastic::Helpers::ButtonsHelper

Included in:
FormBuilder
Defined in:
lib/formtastic/helpers/buttons_helper.rb

Overview

ButtonsHelper encapsulates the responsibilties of the #buttons and #commit_button helpers for submitting forms.

#buttons is used to wrap the form's button(s) and actions in a <fieldset> and <ol>, with each item in the list containing the markup representing a single button.

#buttons is usually called with a block containing a single #commit_button call:

<%= semantic_form_for @post do |f| %>
  ...
  <%= f.buttons do %>
    <%= f.commit_button
  <% end %>
<% end %>

The HTML output will be something like:

<form class="formtastic" method="post" action="...">
  ...
  <fieldset class="buttons">
    <ol>
      <li class="commit">
        <input type="submit" name="commit" value="Create Post" class="create">
      </li>
    </ol>
  </fieldset>
</form>

While this may seem slightly over-engineered, it is consistent with the way form inputs are handled, and makes room for other types of buttons and actions in future versions (such as cancel buttons or links, reset buttons and even alternate actions like 'save and continue editing').

It's important to note that the semantic_form_for and #buttons blocks wrap the standard Rails form_for helper and form builder, so you have full access to every standard Rails form helper, with any HTML markup and ERB syntax, allowing you to "break free" from Formtastic when it doesn't suit to create your own buttons, links and actions:

<%= semantic_form_for @post do |f| %>
  ...
  <%= f.buttons do %>
    <li class="save">
      <%= f.submit "Save" %>
    <li>
    <li class="cancel-link">
      Or <%= link_to "Cancel", posts_url %>
    <li>
  <% end %>
<% end %>

There are many other syntax variations and arguments to customize your form. See the full documentation of #buttons and #commit_button for details.