formtastic 2.0.2 → 2.1.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -1
- data/Appraisals +11 -0
- data/CHANGELOG +2 -2
- data/Gemfile +0 -2
- data/README.textile +183 -151
- data/Rakefile +9 -5
- data/app/assets/stylesheets/formtastic.css +16 -3
- data/formtastic.gemspec +6 -2
- data/gemfiles/rails-3.0.gemfile +7 -0
- data/gemfiles/rails-3.1.gemfile +7 -0
- data/gemfiles/rails-3.2.gemfile +7 -0
- data/lib/formtastic.rb +10 -2
- data/lib/formtastic/actions.rb +11 -0
- data/lib/formtastic/actions/base.rb +156 -0
- data/lib/formtastic/actions/button_action.rb +72 -0
- data/lib/formtastic/actions/buttonish.rb +17 -0
- data/lib/formtastic/actions/input_action.rb +68 -0
- data/lib/formtastic/actions/link_action.rb +87 -0
- data/lib/formtastic/engine.rb +5 -1
- data/lib/formtastic/form_builder.rb +3 -0
- data/lib/formtastic/helpers.rb +2 -1
- data/lib/formtastic/helpers/action_helper.rb +109 -0
- data/lib/formtastic/helpers/actions_helper.rb +168 -0
- data/lib/formtastic/helpers/buttons_helper.rb +22 -9
- data/lib/formtastic/helpers/errors_helper.rb +0 -54
- data/lib/formtastic/helpers/fieldset_wrapper.rb +10 -5
- data/lib/formtastic/helpers/form_helper.rb +2 -2
- data/lib/formtastic/helpers/input_helper.rb +1 -10
- data/lib/formtastic/helpers/inputs_helper.rb +6 -3
- data/lib/formtastic/i18n.rb +3 -2
- data/lib/formtastic/inputs/base.rb +11 -3
- data/lib/formtastic/inputs/base/choices.rb +6 -1
- data/lib/formtastic/inputs/base/collections.rb +36 -13
- data/lib/formtastic/inputs/base/grouped_collections.rb +1 -1
- data/lib/formtastic/inputs/base/numeric.rb +50 -0
- data/lib/formtastic/inputs/base/options.rb +1 -1
- data/lib/formtastic/inputs/base/placeholder.rb +17 -0
- data/lib/formtastic/inputs/base/stringish.rb +2 -7
- data/lib/formtastic/inputs/base/timeish.rb +21 -5
- data/lib/formtastic/inputs/base/validations.rb +1 -1
- data/lib/formtastic/inputs/base/wrapping.rb +10 -3
- data/lib/formtastic/inputs/boolean_input.rb +10 -2
- data/lib/formtastic/inputs/check_boxes_input.rb +18 -9
- data/lib/formtastic/inputs/country_input.rb +2 -2
- data/lib/formtastic/inputs/date_input.rb +19 -1
- data/lib/formtastic/inputs/datetime_input.rb +1 -1
- data/lib/formtastic/inputs/email_input.rb +2 -1
- data/lib/formtastic/inputs/file_input.rb +1 -1
- data/lib/formtastic/inputs/hidden_input.rb +1 -1
- data/lib/formtastic/inputs/number_input.rb +6 -36
- data/lib/formtastic/inputs/password_input.rb +2 -1
- data/lib/formtastic/inputs/phone_input.rb +3 -2
- data/lib/formtastic/inputs/radio_input.rb +1 -1
- data/lib/formtastic/inputs/range_input.rb +8 -32
- data/lib/formtastic/inputs/search_input.rb +2 -1
- data/lib/formtastic/inputs/select_input.rb +56 -28
- data/lib/formtastic/inputs/string_input.rb +3 -1
- data/lib/formtastic/inputs/text_input.rb +5 -4
- data/lib/formtastic/inputs/time_input.rb +4 -8
- data/lib/formtastic/inputs/time_zone_input.rb +1 -1
- data/lib/formtastic/inputs/url_input.rb +2 -1
- data/lib/formtastic/localized_string.rb +6 -94
- data/lib/formtastic/localizer.rb +110 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/formtastic/form/form_generator.rb +105 -0
- data/lib/generators/templates/_form.html.erb +2 -2
- data/lib/generators/templates/_form.html.haml +4 -4
- data/lib/generators/templates/_form.html.slim +2 -2
- data/lib/generators/templates/formtastic.rb +4 -0
- data/lib/locale/en.yml +2 -0
- data/sample/basic_inputs.html +22 -0
- data/spec/actions/button_action_spec.rb +63 -0
- data/spec/actions/generic_action_spec.rb +484 -0
- data/spec/actions/input_action_spec.rb +59 -0
- data/spec/actions/link_action_spec.rb +92 -0
- data/spec/builder/semantic_fields_for_spec.rb +14 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +118 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +47 -0
- data/spec/helpers/action_helper_spec.rb +365 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/buttons_helper_spec.rb +39 -23
- data/spec/helpers/commit_button_helper_spec.rb +153 -93
- data/spec/helpers/inputs_helper_spec.rb +14 -0
- data/spec/i18n_spec.rb +11 -0
- data/spec/inputs/boolean_input_spec.rb +31 -2
- data/spec/inputs/check_boxes_input_spec.rb +29 -1
- data/spec/inputs/date_input_spec.rb +95 -0
- data/spec/inputs/datetime_input_spec.rb +49 -0
- data/spec/inputs/email_input_spec.rb +28 -0
- data/spec/inputs/file_input_spec.rb +28 -0
- data/spec/inputs/hidden_input_spec.rb +28 -0
- data/spec/inputs/include_blank_spec.rb +53 -45
- data/spec/inputs/number_input_spec.rb +34 -4
- data/spec/inputs/password_input_spec.rb +28 -0
- data/spec/inputs/phone_input_spec.rb +28 -0
- data/spec/inputs/placeholder_spec.rb +10 -10
- data/spec/inputs/radio_input_spec.rb +51 -6
- data/spec/inputs/range_input_spec.rb +30 -2
- data/spec/inputs/search_input_spec.rb +27 -0
- data/spec/inputs/select_input_spec.rb +52 -6
- data/spec/inputs/string_input_spec.rb +28 -0
- data/spec/inputs/text_input_spec.rb +27 -0
- data/spec/inputs/time_input_spec.rb +67 -1
- data/spec/inputs/time_zone_input_spec.rb +28 -0
- data/spec/inputs/url_input_spec.rb +28 -0
- data/spec/inputs/with_options_spec.rb +43 -0
- data/spec/spec_helper.rb +22 -6
- data/spec/support/custom_macros.rb +6 -134
- data/spec/support/test_environment.rb +0 -1
- metadata +104 -17
- data/lib/formtastic/helpers/semantic_form_helper.rb +0 -11
- data/lib/formtastic/inputs/numeric_input.rb +0 -21
- data/lib/formtastic/railtie.rb +0 -12
- data/lib/formtastic/semantic_form_builder.rb +0 -11
- data/spec/builder/errors_spec.rb +0 -203
- data/spec/inputs/numeric_input_spec.rb +0 -41
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Outputs a link wrapped in the standard `<li>` wrapper. This the default for `:cancel` actions.
|
|
2
|
+
# The link's URL defaults to Rails' built-in `:back` macro (the HTTP referrer, or Javascript for the
|
|
3
|
+
# browser's history), but can be altered with the `:url` option.
|
|
4
|
+
#
|
|
5
|
+
# @example The `:as` can be ommitted, these are functionally equivalent
|
|
6
|
+
# <%= f.action :cancel, :as => :link %>
|
|
7
|
+
# <%= f.action :cancel %>
|
|
8
|
+
#
|
|
9
|
+
# @example Full form context and output
|
|
10
|
+
#
|
|
11
|
+
# <%= semantic_form_for(@post) do |f| %>
|
|
12
|
+
# <%= f.actions do %>
|
|
13
|
+
# <%= f.action :submit, :as => :input %>
|
|
14
|
+
# <%= f.action :cancel, :as => :link %>
|
|
15
|
+
# <% end %>
|
|
16
|
+
# <% end %>
|
|
17
|
+
#
|
|
18
|
+
# <form...>
|
|
19
|
+
# <fieldset class="actions">
|
|
20
|
+
# <ol>
|
|
21
|
+
# <li class="action input_action" id="post_submit_action">
|
|
22
|
+
# <input type="reset" value="Reset">
|
|
23
|
+
# </li>
|
|
24
|
+
# <li class="action link_action" id="post_reset_action">
|
|
25
|
+
# <a href="javascript:history.back()">Cancel</a>
|
|
26
|
+
# </li>
|
|
27
|
+
# </ol>
|
|
28
|
+
# </fieldset>
|
|
29
|
+
# </form>
|
|
30
|
+
#
|
|
31
|
+
# @example Modifying the URL for the link
|
|
32
|
+
# <%= f.action :cancel, :as => :link, :url => "http://example.com/path" %>
|
|
33
|
+
# <%= f.action :cancel, :as => :link, :url => "/path" %>
|
|
34
|
+
# <%= f.action :cancel, :as => :link, :url => posts_path %>
|
|
35
|
+
# <%= f.action :cancel, :as => :link, :url => url_for(...) %>
|
|
36
|
+
# <%= f.action :cancel, :as => :link, :url => { :controller => "posts", :action => "index" } %>
|
|
37
|
+
#
|
|
38
|
+
# @example Specifying a label with a String
|
|
39
|
+
# <%= f.action :cancel, :as => :link, :label => "Stop" %>
|
|
40
|
+
#
|
|
41
|
+
# @example Pass HTML attributes down to the `<a>`
|
|
42
|
+
# <%= f.action :cancel, :as => :link, :button_html => { :class => 'pretty', :accesskey => 'x' } %>
|
|
43
|
+
#
|
|
44
|
+
# @example Access key can also be set as a top-level option
|
|
45
|
+
# <%= f.action :cancel, :as => :link, :accesskey => 'x' %>
|
|
46
|
+
#
|
|
47
|
+
# @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
|
|
48
|
+
# <%= f.action :cancel, :as => :link, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
|
|
49
|
+
# <%= f.action :cancel, :as => :link, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
|
|
50
|
+
#
|
|
51
|
+
# @option *args :label [String, Symbol]
|
|
52
|
+
# Override the label text with a String or a symbol for an i18n translation key
|
|
53
|
+
#
|
|
54
|
+
# @option *args :button_html [Hash]
|
|
55
|
+
# Override or add to the HTML attributes to be passed down to the `<a>` tag
|
|
56
|
+
#
|
|
57
|
+
# @option *args :wrapper_html [Hash]
|
|
58
|
+
# Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
|
|
59
|
+
#
|
|
60
|
+
# @todo document i18n keys
|
|
61
|
+
# @todo document i18n translation with :label (?)
|
|
62
|
+
# @todo :prefix and :suffix options? (can also be done with CSS or subclassing for custom Actions)
|
|
63
|
+
module Formtastic
|
|
64
|
+
module Actions
|
|
65
|
+
class LinkAction
|
|
66
|
+
|
|
67
|
+
include Base
|
|
68
|
+
|
|
69
|
+
def supported_methods
|
|
70
|
+
[:cancel]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# TODO reset_action class?
|
|
74
|
+
def to_html
|
|
75
|
+
wrapper do
|
|
76
|
+
template.link_to(text, url, button_html)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def url
|
|
81
|
+
return options[:url] if options.key?(:url)
|
|
82
|
+
:back
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
data/lib/formtastic/engine.rb
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
# Configure Rails 3.1 to have assert_select_jquery() in tests
|
|
2
1
|
module Formtastic
|
|
3
2
|
# Required for formtastic.css to be discoverable in the asset pipeline
|
|
4
3
|
# @private
|
|
5
4
|
class Engine < ::Rails::Engine
|
|
5
|
+
initializer 'formtastic.initialize' do
|
|
6
|
+
ActiveSupport.on_load(:action_view) do
|
|
7
|
+
include Formtastic::Helpers::FormHelper
|
|
8
|
+
end
|
|
9
|
+
end
|
|
6
10
|
end
|
|
7
11
|
end
|
|
@@ -23,6 +23,7 @@ module Formtastic
|
|
|
23
23
|
configure :file_metadata_suffixes, ['content_type', 'file_name', 'file_size']
|
|
24
24
|
configure :priority_countries, ["Australia", "Canada", "United Kingdom", "United States"]
|
|
25
25
|
configure :i18n_lookups_by_default, true
|
|
26
|
+
configure :i18n_localizer, Formtastic::Localizer
|
|
26
27
|
configure :escape_html_entities_in_hints_and_labels, true
|
|
27
28
|
configure :default_commit_button_accesskey
|
|
28
29
|
configure :default_inline_error_class, 'inline-errors'
|
|
@@ -40,6 +41,8 @@ module Formtastic
|
|
|
40
41
|
include Formtastic::Helpers::InputHelper
|
|
41
42
|
include Formtastic::Helpers::InputsHelper
|
|
42
43
|
include Formtastic::Helpers::ButtonsHelper
|
|
44
|
+
include Formtastic::Helpers::ActionHelper
|
|
45
|
+
include Formtastic::Helpers::ActionsHelper
|
|
43
46
|
include Formtastic::Helpers::ErrorsHelper
|
|
44
47
|
|
|
45
48
|
# This is a wrapper around Rails' `ActionView::Helpers::FormBuilder#fields_for`, originally
|
data/lib/formtastic/helpers.rb
CHANGED
|
@@ -2,6 +2,8 @@ module Formtastic
|
|
|
2
2
|
# @private
|
|
3
3
|
module Helpers
|
|
4
4
|
autoload :ButtonsHelper, 'formtastic/helpers/buttons_helper'
|
|
5
|
+
autoload :ActionHelper, 'formtastic/helpers/action_helper'
|
|
6
|
+
autoload :ActionsHelper, 'formtastic/helpers/actions_helper'
|
|
5
7
|
autoload :ErrorsHelper, 'formtastic/helpers/errors_helper'
|
|
6
8
|
autoload :FieldsetWrapper, 'formtastic/helpers/fieldset_wrapper'
|
|
7
9
|
autoload :FileColumnDetection, 'formtastic/helpers/file_column_detection'
|
|
@@ -9,7 +11,6 @@ module Formtastic
|
|
|
9
11
|
autoload :InputHelper, 'formtastic/helpers/input_helper'
|
|
10
12
|
autoload :InputsHelper, 'formtastic/helpers/inputs_helper'
|
|
11
13
|
autoload :LabelHelper, 'formtastic/helpers/label_helper'
|
|
12
|
-
autoload :SemanticFormHelper, 'formtastic/helpers/semantic_form_helper'
|
|
13
14
|
autoload :Reflection, 'formtastic/helpers/reflection'
|
|
14
15
|
end
|
|
15
16
|
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Helpers
|
|
4
|
+
module ActionHelper
|
|
5
|
+
|
|
6
|
+
# Renders an action for the form (such as a subit/reset button, or a cancel link).
|
|
7
|
+
#
|
|
8
|
+
# Each action is wrapped in an `<li class="action">` tag with other classes added based on the
|
|
9
|
+
# type of action being rendered, and is intended to be rendered inside a {#buttons}
|
|
10
|
+
# block which wraps the button in a `fieldset` and `ol`.
|
|
11
|
+
#
|
|
12
|
+
# The textual value of the label can be changed from the default through the `:label`
|
|
13
|
+
# argument or through i18n.
|
|
14
|
+
#
|
|
15
|
+
# @example Basic usage
|
|
16
|
+
# # form
|
|
17
|
+
# <%= semantic_form_for @post do |f| %>
|
|
18
|
+
# ...
|
|
19
|
+
# <%= f.actions do %>
|
|
20
|
+
# <%= f.action(:submit) %>
|
|
21
|
+
# <%= f.action(:reset) %>
|
|
22
|
+
# <%= f.action(:cancel) %>
|
|
23
|
+
# <% end %>
|
|
24
|
+
# <% end %>
|
|
25
|
+
#
|
|
26
|
+
# # output
|
|
27
|
+
# <form ...>
|
|
28
|
+
# ...
|
|
29
|
+
# <fieldset class="buttons">
|
|
30
|
+
# <ol>
|
|
31
|
+
# <li class="action input_action">
|
|
32
|
+
# <input name="commit" type="submit" value="Create Post">
|
|
33
|
+
# </li>
|
|
34
|
+
# <li class="action input_action">
|
|
35
|
+
# <input name="commit" type="reset" value="Reset Post">
|
|
36
|
+
# </li>
|
|
37
|
+
# <li class="action link_action">
|
|
38
|
+
# <a href="/posts">Cancel Post</a>
|
|
39
|
+
# </li>
|
|
40
|
+
# </ol>
|
|
41
|
+
# </fieldset>
|
|
42
|
+
# </form>
|
|
43
|
+
#
|
|
44
|
+
# @example Set the value through the `:label` option
|
|
45
|
+
# <%= f.action :submit, :label => "Go" %>
|
|
46
|
+
#
|
|
47
|
+
# @example Pass HTML attributes down to the tag inside the wrapper
|
|
48
|
+
# <%= f.action :submit, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
|
|
49
|
+
#
|
|
50
|
+
# @example Pass HTML attributes down to the `<li>` wrapper
|
|
51
|
+
# <%= f.action :submit, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
|
|
52
|
+
#
|
|
53
|
+
# @option *args :label [String, Symbol]
|
|
54
|
+
# Override the label text with a String or a symbold for an i18n translation key
|
|
55
|
+
#
|
|
56
|
+
# @option *args :button_html [Hash]
|
|
57
|
+
# Override or add to the HTML attributes to be passed down to the `<input>` tag
|
|
58
|
+
#
|
|
59
|
+
# @option *args :wrapper_html [Hash]
|
|
60
|
+
# Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
|
|
61
|
+
#
|
|
62
|
+
# @todo document i18n keys
|
|
63
|
+
def action(method, options = {})
|
|
64
|
+
options = options.dup # Allow options to be shared without being tainted by Formtastic
|
|
65
|
+
options[:as] ||= default_action_type(method, options)
|
|
66
|
+
|
|
67
|
+
klass = action_class(options[:as])
|
|
68
|
+
|
|
69
|
+
klass.new(self, template, @object, @object_name, method, options).to_html
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
protected
|
|
73
|
+
|
|
74
|
+
def default_action_type(method, options = {}) #:nodoc:
|
|
75
|
+
case method
|
|
76
|
+
when :submit then :input
|
|
77
|
+
when :reset then :input
|
|
78
|
+
when :cancel then :link
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def action_class(as)
|
|
83
|
+
@input_classes_cache ||= {}
|
|
84
|
+
@input_classes_cache[as] ||= begin
|
|
85
|
+
begin
|
|
86
|
+
begin
|
|
87
|
+
custom_action_class_name(as).constantize
|
|
88
|
+
rescue NameError
|
|
89
|
+
standard_action_class_name(as).constantize
|
|
90
|
+
end
|
|
91
|
+
rescue NameError
|
|
92
|
+
raise Formtastic::UnknownActionError
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# :as => :button # => ButtonAction
|
|
98
|
+
def custom_action_class_name(as)
|
|
99
|
+
"#{as.to_s.camelize}Action"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# :as => :button # => Formtastic::Actions::ButtonAction
|
|
103
|
+
def standard_action_class_name(as)
|
|
104
|
+
"Formtastic::Actions::#{as.to_s.camelize}Action"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Helpers
|
|
3
|
+
# ActionsHelper encapsulates the responsibilties of the {#actions} DSL for acting on
|
|
4
|
+
# (submitting, cancelling, resetting) forms.
|
|
5
|
+
#
|
|
6
|
+
# {#actions} is a block helper used to wrap the form's actions (buttons, links) in a
|
|
7
|
+
# `<fieldset>` and `<ol>`, with each item in the list containing the markup representing a
|
|
8
|
+
# single action.
|
|
9
|
+
#
|
|
10
|
+
# <%= semantic_form_for @post do |f| %>
|
|
11
|
+
# ...
|
|
12
|
+
# <%= f.actions do %>
|
|
13
|
+
# <%= f.action(:submit)
|
|
14
|
+
# <%= f.action(:cancel)
|
|
15
|
+
# <% end %>
|
|
16
|
+
# <% end %>
|
|
17
|
+
#
|
|
18
|
+
# The HTML output will be something like:
|
|
19
|
+
#
|
|
20
|
+
# <form class="formtastic" method="post" action="...">
|
|
21
|
+
# ...
|
|
22
|
+
# <fieldset class="actions">
|
|
23
|
+
# <ol>
|
|
24
|
+
# <li class="action input_action">
|
|
25
|
+
# <input type="submit" name="commit" value="Create Post">
|
|
26
|
+
# </li>
|
|
27
|
+
# <li class="action input_action">
|
|
28
|
+
# <a href="/posts">Cancel Post</a>
|
|
29
|
+
# </li>
|
|
30
|
+
# </ol>
|
|
31
|
+
# </fieldset>
|
|
32
|
+
# </form>
|
|
33
|
+
#
|
|
34
|
+
# It's important to note that the `semantic_form_for` and {#actions} blocks wrap the
|
|
35
|
+
# standard Rails `form_for` helper and form builder, so you have full access to every standard
|
|
36
|
+
# Rails form helper, with any HTML markup and ERB syntax, allowing you to "break free" from
|
|
37
|
+
# Formtastic when it doesn't suit to create your own buttons, links and actions:
|
|
38
|
+
#
|
|
39
|
+
# <%= semantic_form_for @post do |f| %>
|
|
40
|
+
# ...
|
|
41
|
+
# <%= f.actions do %>
|
|
42
|
+
# <li class="save">
|
|
43
|
+
# <%= f.submit "Save" %>
|
|
44
|
+
# <li>
|
|
45
|
+
# <li class="cancel-link">
|
|
46
|
+
# Or <%= link_to "Cancel", posts_url %>
|
|
47
|
+
# <li>
|
|
48
|
+
# <% end %>
|
|
49
|
+
# <% end %>
|
|
50
|
+
#
|
|
51
|
+
# There are many other syntax variations and arguments to customize your form. See the
|
|
52
|
+
# full documentation of {#actions} and {#action} for details.
|
|
53
|
+
module ActionsHelper
|
|
54
|
+
|
|
55
|
+
include Formtastic::Helpers::FieldsetWrapper
|
|
56
|
+
|
|
57
|
+
# Creates a fieldset and ol tag wrapping for use around a set of buttons. It can be
|
|
58
|
+
# called either with a block (in which you can do the usual Rails form stuff, HTML, ERB, etc),
|
|
59
|
+
# or with a list of named actions. These two examples are functionally equivalent:
|
|
60
|
+
#
|
|
61
|
+
# # With a block:
|
|
62
|
+
# <% semantic_form_for @post do |f| %>
|
|
63
|
+
# ...
|
|
64
|
+
# <% f.actions do %>
|
|
65
|
+
# <%= f.action(:submit) %>
|
|
66
|
+
# <%= f.action(:cancel) %>
|
|
67
|
+
# <% end %>
|
|
68
|
+
# <% end %>
|
|
69
|
+
#
|
|
70
|
+
# # With a list of fields:
|
|
71
|
+
# <% semantic_form_for @post do |f| %>
|
|
72
|
+
# <%= f.actions :submit, :cancel %>
|
|
73
|
+
# <% end %>
|
|
74
|
+
#
|
|
75
|
+
# # Output:
|
|
76
|
+
# <form ...>
|
|
77
|
+
# <fieldset class="buttons">
|
|
78
|
+
# <ol>
|
|
79
|
+
# <li class="action input_action">
|
|
80
|
+
# <input type="submit" ...>
|
|
81
|
+
# </li>
|
|
82
|
+
# <li class="action link_action">
|
|
83
|
+
# <a href="...">...</a>
|
|
84
|
+
# </li>
|
|
85
|
+
# </ol>
|
|
86
|
+
# </fieldset>
|
|
87
|
+
# </form>
|
|
88
|
+
#
|
|
89
|
+
# All options except `:name` and `:title` are passed down to the fieldset as HTML
|
|
90
|
+
# attributes (`id`, `class`, `style`...). If provided, the `:name` or `:title` option is
|
|
91
|
+
# passed into a `<legend>` inside the `<fieldset>` to name the set of buttons.
|
|
92
|
+
#
|
|
93
|
+
# @example Quickly add button(s) to the form, accepting all default values, options and behaviors
|
|
94
|
+
# <% semantic_form_for @post do |f| %>
|
|
95
|
+
# ...
|
|
96
|
+
# <%= f.actions %>
|
|
97
|
+
# <% end %>
|
|
98
|
+
#
|
|
99
|
+
# @example Specify which named buttons you want, accepting all default values, options and behaviors
|
|
100
|
+
# <% semantic_form_for @post do |f| %>
|
|
101
|
+
# ...
|
|
102
|
+
# <%= f.actions :commit %>
|
|
103
|
+
# <% end %>
|
|
104
|
+
#
|
|
105
|
+
# @example Specify which named buttons you want, and name the fieldset
|
|
106
|
+
# <% semantic_form_for @post do |f| %>
|
|
107
|
+
# ...
|
|
108
|
+
# <%= f.actions :commit, :name => "Actions" %>
|
|
109
|
+
# or
|
|
110
|
+
# <%= f.actions :commit, :label => "Actions" %>
|
|
111
|
+
# <% end %>
|
|
112
|
+
#
|
|
113
|
+
# @example Get full control over the action options
|
|
114
|
+
# <% semantic_form_for @post do |f| %>
|
|
115
|
+
# ...
|
|
116
|
+
# <%= f.actions do %>
|
|
117
|
+
# <%= f.action :label => "Go", :button_html => { :class => "pretty" :disable_with => "Wait..." }, :wrapper_html => { ... }
|
|
118
|
+
# <% end %>
|
|
119
|
+
# <% end %>
|
|
120
|
+
#
|
|
121
|
+
# @example Make your own actions with standard Rails helpers or HTML
|
|
122
|
+
# <% semantic_form_for @post do |f| %>
|
|
123
|
+
# <%= f.actions do %>
|
|
124
|
+
# <li>
|
|
125
|
+
# ...
|
|
126
|
+
# </li>
|
|
127
|
+
# <% end %>
|
|
128
|
+
# <% end %>
|
|
129
|
+
#
|
|
130
|
+
# @example Add HTML attributes to the fieldset
|
|
131
|
+
# <% semantic_form_for @post do |f| %>
|
|
132
|
+
# ...
|
|
133
|
+
# <%= f.actions :commit, :style => "border:1px;" %>
|
|
134
|
+
# or
|
|
135
|
+
# <%= f.actions :style => "border:1px;" do %>
|
|
136
|
+
# ...
|
|
137
|
+
# <% end %>
|
|
138
|
+
# <% end %>
|
|
139
|
+
#
|
|
140
|
+
# @option *args :label [String, Symbol]
|
|
141
|
+
# Optionally specify text for the legend of the fieldset
|
|
142
|
+
#
|
|
143
|
+
# @option *args :name [String, Symbol]
|
|
144
|
+
# Optionally specify text for the legend of the fieldset (alias for `:label`)
|
|
145
|
+
#
|
|
146
|
+
# @todo document i18n keys
|
|
147
|
+
def actions(*args, &block)
|
|
148
|
+
html_options = args.extract_options!
|
|
149
|
+
html_options[:class] ||= "actions"
|
|
150
|
+
|
|
151
|
+
if block_given?
|
|
152
|
+
field_set_and_list_wrapping(html_options, &block)
|
|
153
|
+
else
|
|
154
|
+
args = default_actions if args.empty?
|
|
155
|
+
contents = args.map { |action_name| action(action_name) }
|
|
156
|
+
field_set_and_list_wrapping(html_options, contents)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
protected
|
|
161
|
+
|
|
162
|
+
def default_actions
|
|
163
|
+
[:submit]
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
@@ -22,7 +22,7 @@ module Formtastic
|
|
|
22
22
|
# ...
|
|
23
23
|
# <fieldset class="buttons">
|
|
24
24
|
# <ol>
|
|
25
|
-
# <li class="commit">
|
|
25
|
+
# <li class="commit button">
|
|
26
26
|
# <input type="submit" name="commit" value="Create Post" class="create">
|
|
27
27
|
# </li>
|
|
28
28
|
# </ol>
|
|
@@ -53,6 +53,8 @@ module Formtastic
|
|
|
53
53
|
#
|
|
54
54
|
# There are many other syntax variations and arguments to customize your form. See the
|
|
55
55
|
# full documentation of {#buttons} and {#commit_button} for details.
|
|
56
|
+
#
|
|
57
|
+
# @deprecated ButtonsHelper will be removed after 2.1
|
|
56
58
|
module ButtonsHelper
|
|
57
59
|
include Formtastic::Helpers::FieldsetWrapper
|
|
58
60
|
include Formtastic::LocalizedString
|
|
@@ -76,9 +78,9 @@ module Formtastic
|
|
|
76
78
|
#
|
|
77
79
|
# # Output:
|
|
78
80
|
# <form ...>
|
|
79
|
-
# <fieldset class="
|
|
81
|
+
# <fieldset class="buttons">
|
|
80
82
|
# <ol>
|
|
81
|
-
# <li class="commit">
|
|
83
|
+
# <li class="commit button">
|
|
82
84
|
# <input type="submit" ...>
|
|
83
85
|
# </li>
|
|
84
86
|
# </ol>
|
|
@@ -164,7 +166,10 @@ module Formtastic
|
|
|
164
166
|
# Optionally specify text for the legend of the fieldset (alias for `:label`)
|
|
165
167
|
#
|
|
166
168
|
# @todo document i18n keys
|
|
169
|
+
# @deprecated f.buttons is deprecated in favor of f.actions and will be removed after 2.1
|
|
167
170
|
def buttons(*args, &block)
|
|
171
|
+
::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")
|
|
172
|
+
|
|
168
173
|
html_options = args.extract_options!
|
|
169
174
|
html_options[:class] ||= "buttons"
|
|
170
175
|
|
|
@@ -203,7 +208,11 @@ module Formtastic
|
|
|
203
208
|
# <form ...>
|
|
204
209
|
# ...
|
|
205
210
|
# <fieldset class="buttons">
|
|
206
|
-
# <
|
|
211
|
+
# <ol>
|
|
212
|
+
# <li class="commit button">
|
|
213
|
+
# <input name="commit" type="submit" value="Create Post" class="create">
|
|
214
|
+
# </li>
|
|
215
|
+
# </ol>
|
|
207
216
|
# </fieldset>
|
|
208
217
|
# </form>
|
|
209
218
|
#
|
|
@@ -234,7 +243,10 @@ module Formtastic
|
|
|
234
243
|
#
|
|
235
244
|
# @todo document i18n keys
|
|
236
245
|
# @todo strange that `:accesskey` seems to be supported in the top level args as well as `:button_html`
|
|
246
|
+
# @deprecated f.commit_button is deprecated in favor of f.actions and will be removed after 2.1
|
|
237
247
|
def commit_button(*args)
|
|
248
|
+
::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")
|
|
249
|
+
|
|
238
250
|
options = args.extract_options!
|
|
239
251
|
text = options.delete(:label) || args.shift
|
|
240
252
|
|
|
@@ -242,6 +254,7 @@ module Formtastic
|
|
|
242
254
|
Formtastic::I18n.t(commit_button_i18n_key, :model => commit_button_object_name)) unless text.is_a?(::String)
|
|
243
255
|
|
|
244
256
|
button_html = options.delete(:button_html) || {}
|
|
257
|
+
button_html[:id] ||= "#{@object_name}_submit"
|
|
245
258
|
button_html.merge!(:class => [button_html[:class], commit_button_i18n_key].compact.join(' '))
|
|
246
259
|
|
|
247
260
|
wrapper_html = options.delete(:wrapper_html) || {}
|
|
@@ -249,7 +262,7 @@ module Formtastic
|
|
|
249
262
|
|
|
250
263
|
accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
|
|
251
264
|
button_html = button_html.merge(:accesskey => accesskey) if accesskey
|
|
252
|
-
|
|
265
|
+
|
|
253
266
|
template.content_tag(:li, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html)
|
|
254
267
|
end
|
|
255
268
|
|
|
@@ -270,10 +283,10 @@ module Formtastic
|
|
|
270
283
|
else
|
|
271
284
|
object_name = @object_name.to_s.send(label_str_method)
|
|
272
285
|
end
|
|
273
|
-
|
|
286
|
+
|
|
274
287
|
object_name
|
|
275
288
|
end
|
|
276
|
-
|
|
289
|
+
|
|
277
290
|
def commit_button_i18n_key
|
|
278
291
|
if new_or_persisted_object?
|
|
279
292
|
key = @object.persisted? ? :update : :create
|
|
@@ -287,11 +300,11 @@ module Formtastic
|
|
|
287
300
|
def commit_button_wrapper_html_class
|
|
288
301
|
['commit', 'button'] # TODO: Add class reflecting on form action.
|
|
289
302
|
end
|
|
290
|
-
|
|
303
|
+
|
|
291
304
|
def new_or_persisted_object?
|
|
292
305
|
@object && (@object.respond_to?(:persisted?) || @object.respond_to?(:new_record?))
|
|
293
306
|
end
|
|
294
|
-
|
|
307
|
+
|
|
295
308
|
end
|
|
296
309
|
end
|
|
297
310
|
end
|