lib/formtastic/helpers/buttons_helper.rb in formtastic-2.0.2 vs lib/formtastic/helpers/buttons_helper.rb in formtastic-2.1.0.beta1
- old
+ new
@@ -20,11 +20,11 @@
#
# <form class="formtastic" method="post" action="...">
# ...
# <fieldset class="buttons">
# <ol>
- # <li class="commit">
+ # <li class="commit button">
# <input type="submit" name="commit" value="Create Post" class="create">
# </li>
# </ol>
# </fieldset>
# </form>
@@ -51,10 +51,12 @@
# <% 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.
+ #
+ # @deprecated ButtonsHelper will be removed after 2.1
module ButtonsHelper
include Formtastic::Helpers::FieldsetWrapper
include Formtastic::LocalizedString
# Creates a fieldset and ol tag wrapping for use around a set of buttons. It can be
@@ -74,13 +76,13 @@
# <%= f.buttons :commit %>
# <% end %>
#
# # Output:
# <form ...>
- # <fieldset class="inputs">
+ # <fieldset class="buttons">
# <ol>
- # <li class="commit">
+ # <li class="commit button">
# <input type="submit" ...>
# </li>
# </ol>
# </fieldset>
# </form>
@@ -162,11 +164,14 @@
#
# @option *args :name [String, Symbol]
# Optionally specify text for the legend of the fieldset (alias for `:label`)
#
# @todo document i18n keys
+ # @deprecated f.buttons is deprecated in favor of f.actions and will be removed after 2.1
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] ||= "buttons"
if block_given?
field_set_and_list_wrapping(html_options, &block)
@@ -201,11 +206,15 @@
#
# # output
# <form ...>
# ...
# <fieldset class="buttons">
- # <input name="commit" type="submit" value="Create Post" class="create">
+ # <ol>
+ # <li class="commit button">
+ # <input name="commit" type="submit" value="Create Post" class="create">
+ # </li>
+ # </ol>
# </fieldset>
# </form>
#
# @example Set the value through the `:label` option
# <%= f.commit_button :label => "Go" %>
@@ -232,26 +241,30 @@
# @option *args :wrapper_html [Hash]
# Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
#
# @todo document i18n keys
# @todo strange that `:accesskey` seems to be supported in the top level args as well as `:button_html`
+ # @deprecated f.commit_button is deprecated in favor of f.actions and will be removed after 2.1
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.content_tag(:li, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html)
end
def commit_button_object_name
if new_or_persisted_object?
@@ -268,14 +281,14 @@
object_name = (object_human_name == crappy_human_name) ? decent_human_name : object_human_name
end
else
object_name = @object_name.to_s.send(label_str_method)
end
-
+
object_name
end
-
+
def commit_button_i18n_key
if new_or_persisted_object?
key = @object.persisted? ? :update : :create
else
key = :submit
@@ -285,13 +298,13 @@
end
def commit_button_wrapper_html_class
['commit', 'button'] # TODO: Add class reflecting on form action.
end
-
+
def new_or_persisted_object?
@object && (@object.respond_to?(:persisted?) || @object.respond_to?(:new_record?))
end
-
+
end
end
end
\ No newline at end of file