Module: FlexaFormtasticBootstrap::Helpers::ButtonsHelper

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

Instance Method Summary collapse

Instance Method Details

#buttons(*args, &block) ⇒ Object

include Formtastic::Helpers::ButtonsHelper



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

def buttons(*args, &block)

  html_options = args.extract_options!
  html_options[:class] ||= "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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/flexa_formtastic_bootstrap/helpers/buttons_helper.rb', line 30

def commit_button(*args)
  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.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