Module: SpeedoFormstrap::Helpers::ButtonsHelper

Includes:
Formtastic::Helpers::ButtonsHelper
Included in:
FormBuilder
Defined in:
lib/speedo-formstrap/helpers/buttons_helper.rb

Instance Method Summary collapse

Instance Method Details

#buttons(*args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/speedo-formstrap/helpers/buttons_helper.rb', line 7

def buttons(*args, &block)
  ::ActiveSupport::Deprecation.warn("f.buttons is deprecated in favour of f.actions and will be removed from Formtastic after 2.1. Please see ActionsHelper and InputAction or ButtonAction for more information")

  html_options = args.extract_options!
  html_options[:class] ||= "form-actions"

  if html_options.has_key?(:name)
    ActiveSupport::Deprecation.warn('The :name option is not supported')
  end

  if block_given?
    template.(:div, html_options) do
      yield
    end
  else
    args = [:commit] if args.empty?
    contents = args.map { |button_name| send(:"#{button_name}_button") }
    template.(:div, html_options.except(:builder, :parent, :name)) do
      Formtastic::Util.html_safe(contents.join)
    end
  end

end

#commit_button(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/speedo-formstrap/helpers/buttons_helper.rb', line 31

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], "btn commit", commit_button_i18n_key].compact.join(' '))

  # TODO We don't have a wrapper. Add deprecation message.
  # 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

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