Method: Formtastic::Helpers::ButtonsHelper#commit_button

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

#commit_button(*args) ⇒ Object

Deprecated.

f.commit_button is deprecated in favor of f.actions and will be removed after 2.1

TODO:

document i18n keys

TODO:

strange that :accesskey seems to be supported in the top level args as well as :button_html

Creates a submit input tag with the value "Save [model name]" (for existing records) or "Create [model name]" (for new records) by default. The output is an <input> tag with the type of submit and a class of either create or update (if Formtastic can determin if) the record is new or not) with submit as a fallback class. The submit button is wrapped in an <li> tag with a class of commit, and is intended to be rendered inside a #buttons block which wraps the button in a fieldset and ol.

The textual value of the label can be changed from this default through the :label argument or through i18n.

You can pass HTML attributes down to the <input> tag with the :button_html option, and pass HTML attributes to the wrapping <li> tag with the :wrapper_html option.

Examples:

Basic usage

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

# output
<form ...>
  ...
  <fieldset class="buttons">
    <ol>
      <li class="commit button">
        <input name="commit" type="submit" value="Create Post" class="create">
      </li>
    </ol>
  </fieldset>
</form>

Set the value through the :label option

<%= f.commit_button :label => "Go" %>

Set the value through the optional first argument (like Rails' f.submit)

<%= f.commit_button "Go" %>

Pass HTML attributes down to the <input>

<%= f.commit_button :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
<%= f.commit_button :label => "Go", :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
<%= f.commit_button "Go", :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>

Pass HTML attributes down to the <li> wrapper

<%= f.commit_button :wrapper_html => { :class => 'special', :id => 'whatever' } %>
<%= f.commit_button :label => "Go", :wrapper_html => { :class => 'special', :id => 'whatever' } %>
<%= f.commit_button "Go", :wrapper_html => { :class => 'special', :id => 'whatever' } %>

Parameters:

  • *args (Hash)

    a customizable set of options



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/formtastic/helpers/buttons_helper.rb', line 247

def commit_button(*args)
  ::ActiveSupport::Deprecation.warn("f.commit_button is deprecated in favour of f.action(:submit) and will be removed from Formtastic after 2.1. Please see ActionsHelper and InputAction or ButtonAction for more information")
  
  options = args.extract_options!
  text = options.delete(:label) || args.shift

  text = (localized_string(commit_button_i18n_key, text, :action, :model => commit_button_object_name) ||
          Formtastic::I18n.t(commit_button_i18n_key, :model => commit_button_object_name)) unless text.is_a?(::String)

  button_html = options.delete(:button_html) || {}
  button_html[:id] ||= "#{@object_name}_submit"
  button_html.merge!(:class => [button_html[:class], commit_button_i18n_key].compact.join(' '))

  wrapper_html = options.delete(:wrapper_html) || {}
  wrapper_html[:class] = (commit_button_wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')

  accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
  button_html = button_html.merge(:accesskey => accesskey) if accesskey

  template.(:li, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html)
end