aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_tag_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_tag_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 4b8484bfb5..d7d9c45120 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -386,6 +386,15 @@ module ActionView
# * <tt>:disabled</tt> - If true, the user will not be able to use this input.
# * Any other key creates standard HTML options for the tag.
#
+ # ==== Data attributes
+ #
+ # * <tt>:confirm => 'question?'</tt> - If present the unobtrusive JavaScript
+ # drivers will provide a prompt with the question specified. If the user accepts,
+ # the form is processed normally, otherwise no action is taken.
+ # * <tt>:disable_with</tt> - Value of this parameter will be used as the value for a
+ # disabled version of the submit button when the form is submitted. This feature is
+ # provided by the unobtrusive JavaScript driver.
+ #
# ==== Examples
# submit_tag
# # => <input name="commit" type="submit" value="Save changes" />
@@ -411,6 +420,18 @@ module ActionView
def submit_tag(value = "Save changes", options = {})
options = options.stringify_keys
+ if disable_with = options.delete("disable_with")
+ ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead"
+
+ options["data-disable-with"] = disable_with
+ end
+
+ if confirm = options.delete("confirm")
+ ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'"
+
+ options["data-confirm"] = confirm
+ end
+
tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options)
end
@@ -427,6 +448,17 @@ module ActionView
# use this input.
# * Any other key creates standard HTML options for the tag.
#
+ # ==== Data attributes
+ #
+ # * <tt>:confirm => 'question?'</tt> - If present, the
+ # unobtrusive JavaScript drivers will provide a prompt with
+ # the question specified. If the user accepts, the form is
+ # processed normally, otherwise no action is taken.
+ # * <tt>:disable_with</tt> - Value of this parameter will be
+ # used as the value for a disabled version of the submit
+ # button when the form is submitted. This feature is provided
+ # by the unobtrusive JavaScript driver.
+ #
# ==== Examples
# button_tag
# # => <button name="button" type="submit">Button</button>
@@ -438,11 +470,26 @@ module ActionView
# # <strong>Ask me!</strong>
# # </button>
#
+ # button_tag "Checkout", :data => { disable_with => "Please wait..." }
+ # # => <button data-disable-with="Please wait..." name="button" type="submit">Checkout</button>
+ #
def button_tag(content_or_options = nil, options = nil, &block)
options = content_or_options if block_given? && content_or_options.is_a?(Hash)
options ||= {}
options = options.stringify_keys
+ if disable_with = options.delete("disable_with")
+ ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead"
+
+ options["data-disable-with"] = disable_with
+ end
+
+ if confirm = options.delete("confirm")
+ ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'"
+
+ options["data-confirm"] = confirm
+ end
+
options.reverse_merge! 'name' => 'button', 'type' => 'submit'
content_tag :button, content_or_options || 'Button', options, &block
@@ -457,6 +504,12 @@ module ActionView
# * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
# * Any other key creates standard HTML options for the tag.
#
+ # ==== Data attributes
+ #
+ # * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm
+ # prompt with the question specified. If the user accepts, the form is
+ # processed normally, otherwise no action is taken.
+ #
# ==== Examples
# image_submit_tag("login.png")
# # => <input src="/images/login.png" type="image" />
@@ -475,6 +528,12 @@ module ActionView
def image_submit_tag(source, options = {})
options = options.stringify_keys
+ if confirm = options.delete("confirm")
+ ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'"
+
+ options["data-confirm"] = confirm
+ end
+
tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options)
end