From fb8a830a329b78a5863c1dbfb70a4005d3de60ec Mon Sep 17 00:00:00 2001 From: Carlos Galdino Date: Fri, 1 Jun 2012 16:54:21 -0300 Subject: Remove `:confirm` in favor of `:data => { :confirm => 'Text' }` option This applies to the following helpers: `button_to` `button_tag` `image_submit_tag` `link_to` `submit_tag` --- .../lib/action_view/helpers/form_tag_helper.rb | 29 +++-------------- actionpack/lib/action_view/helpers/url_helper.rb | 38 +++++++++------------- 2 files changed, 21 insertions(+), 46 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 1a0019a48c..4b8484bfb5 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -382,9 +382,7 @@ module ActionView # Creates a submit button with the text value as the caption. # # ==== Options - # * :confirm => 'question?' - 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. + # * :data - This option can be used to add custom data attributes. # * :disabled - If true, the user will not be able to use this input. # * Any other key creates standard HTML options for the tag. # @@ -407,16 +405,12 @@ module ActionView # submit_tag "Edit", :class => "edit_button" # # => # - # submit_tag "Save", :confirm => "Are you sure?" + # submit_tag "Save", :data => { :confirm => "Are you sure?" } # # => # def submit_tag(value = "Save changes", options = {}) options = options.stringify_keys - if confirm = options.delete("confirm") - options["data-confirm"] = confirm - end - tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options) end @@ -428,10 +422,7 @@ module ActionView # so this helper will also accept a block. # # ==== Options - # * :confirm => 'question?' - 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. + # * :data - This option can be used to add custom data attributes. # * :disabled - If true, the user will not be able to # use this input. # * Any other key creates standard HTML options for the tag. @@ -452,10 +443,6 @@ module ActionView options ||= {} options = options.stringify_keys - if confirm = options.delete("confirm") - options["data-confirm"] = confirm - end - options.reverse_merge! 'name' => 'button', 'type' => 'submit' content_tag :button, content_or_options || 'Button', options, &block @@ -466,9 +453,7 @@ module ActionView # source is passed to AssetTagHelper#path_to_image # # ==== Options - # * :confirm => 'question?' - 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. + # * :data - This option can be used to add custom data attributes. # * :disabled - If set to true, the user will not be able to use this input. # * Any other key creates standard HTML options for the tag. # @@ -485,15 +470,11 @@ module ActionView # image_submit_tag("agree.png", :disabled => true, :class => "agree_disagree_button") # # => # - # image_submit_tag("save.png", :confirm => "Are you sure?") + # image_submit_tag("save.png", :data => { :confirm => "Are you sure?" }) # # => def image_submit_tag(source, options = {}) options = options.stringify_keys - if confirm = options.delete("confirm") - options["data-confirm"] = confirm - end - tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options) end diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 736f9fa2f0..b4eb3d4826 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -132,8 +132,7 @@ module ActionView # # posts_path # # link_to(body, url_options = {}, html_options = {}) - # # url_options, except :confirm or :method, - # # is passed to url_for + # # url_options, except :method, is passed to url_for # # link_to(options = {}, html_options = {}) do # # name @@ -144,9 +143,7 @@ module ActionView # end # # ==== Options - # * :confirm => 'question?' - This will allow the unobtrusive JavaScript - # driver to prompt with the question specified. If the user accepts, the link is - # processed normally, otherwise no action is taken. + # * :data - This option can be used to add custom data attributes. # * :method => symbol of HTTP verb - This modifier will dynamically # create an HTML form and immediately submit the form for processing using # the HTTP verb specified. Useful for having links perform a POST operation @@ -226,13 +223,15 @@ module ActionView # link_to "Nonsense search", searches_path(:foo => "bar", :baz => "quux") # # => Nonsense search # - # The two options specific to +link_to+ (:confirm and :method) are used as follows: + # The only option specific to +link_to+ (:method) is used as follows: # - # link_to "Visit Other Site", "http://www.rubyonrails.org/", :confirm => "Are you sure?" - # # => Visit Other Site + # link_to("Destroy", "http://www.example.com", :method => :delete) + # # => Destroy + # + # You can also use custom data attributes using the :data option: # - # link_to("Destroy", "http://www.example.com", :method => :delete, :confirm => "Are you sure?") - # # => Destroy + # link_to "Visit Other Site", "http://www.rubyonrails.org/", :data => { :confirm => "Are you sure?" } + # # => Visit Other Site def link_to(name = nil, options = nil, html_options = nil, &block) html_options, options = options, name if block_given? options ||= {} @@ -255,10 +254,9 @@ module ActionView # to allow styling of the form itself and its children. This can be changed # using the :form_class modifier within +html_options+. You can control # the form submission and input element behavior using +html_options+. - # This method accepts the :method and :confirm modifiers - # described in the +link_to+ documentation. If no :method modifier - # is given, it will default to performing a POST operation. You can also - # disable the button by passing :disabled => true in +html_options+. + # This method accepts the :method modifier described in the +link_to+ documentation. + # If no :method modifier is given, it will default to performing a POST operation. + # You can also disable the button by passing :disabled => true in +html_options+. # If you are using RESTful routes, you can pass the :method # to change the HTTP verb used to submit the form. # @@ -269,9 +267,7 @@ module ActionView # * :method - Symbol of HTTP verb. Supported verbs are :post, :get, # :delete, :patch, and :put. By default it will be :post. # * :disabled - If set to true, it will generate a disabled button. - # * :confirm - This will use the unobtrusive JavaScript driver to - # prompt with the question specified. If the user accepts, the link is - # processed normally, otherwise no action is taken. + # * :data - This option can be used to add custom data attributes. # * :remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the # submit behavior. By default this behavior is an ajax submit. # * :form - This hash will be form attributes @@ -311,7 +307,7 @@ module ActionView # # # <%= button_to "Delete Image", { :action => "delete", :id => @image.id }, - # :confirm => "Are you sure?", :method => :delete %> + # :method => :delete, :data => { :confirm => "Are you sure?" } %> # # => "
# #
# # @@ -321,8 +317,8 @@ module ActionView # # " # # - # <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', - # :method => "delete", :remote => true) %> + # <%= button_to('Destroy', 'http://www.example.com', + # :method => "delete", :remote => true, :data => { :confirm' => 'Are you sure?' }) %> # # => "
# #
# # @@ -627,10 +623,8 @@ module ActionView html_options = html_options.stringify_keys html_options['data-remote'] = 'true' if link_to_remote_options?(options) || link_to_remote_options?(html_options) - confirm = html_options.delete('confirm') method = html_options.delete('method') - html_options["data-confirm"] = confirm if confirm add_method_to_attributes!(html_options, method) if method html_options -- cgit v1.2.3