From a9e89e82b67f721fe68ca58a2d371b666cdb7441 Mon Sep 17 00:00:00 2001 From: "Stephen St. Martin" Date: Sun, 31 Jan 2010 14:03:37 -0500 Subject: add :remote option to form_tag --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib/action_view/helpers/form_tag_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index fb32f78e5b..81c76e090a 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -441,6 +441,7 @@ module ActionView returning options.stringify_keys do |html_options| html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart") html_options["action"] = url_for(url_for_options, *parameters_for_url) + html_options["data-remote"] = true if html_options.delete("remote") end end -- cgit v1.2.3 From c493370f332715dee0ef795a66e896d7f0471cbe Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Sun, 31 Jan 2010 16:30:21 -0600 Subject: UJS documentation. --- .../lib/action_view/helpers/form_tag_helper.rb | 29 ++++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_view/helpers/form_tag_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 81c76e090a..597cf311cb 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -19,6 +19,8 @@ module ActionView # If "put", "delete", or another verb is used, a hidden input with name _method # is added to simulate the verb over post. # * A list of parameters to feed to the URL the form will be posted to. + # * :remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the + # submit behaviour. By default this behaviour is an ajax submit. # # ==== Examples # form_tag('/posts') @@ -30,10 +32,14 @@ module ActionView # form_tag('/upload', :multipart => true) # # =>
# - # <% form_tag '/posts' do -%> + # <% form_tag('/posts')do -%> #
<%= submit_tag 'Save' %>
# <% end -%> # # =>
+ # + # <% form_tag('/posts', :remote => true) %> + # # =>
+ # def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block) html_options = html_options_for_form(url_for_options, options, *parameters_for_url) if block_given? @@ -333,12 +339,13 @@ module ActionView # Creates a submit button with the text value as the caption. # # ==== 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. + # * :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. # * :disabled - If true, the user will not be able to use this input. - # * :disable_with - Value of this parameter will be used as the value for a disabled version - # of the submit button when the form is submitted. + # * :disable_with - 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. # * Any other key creates standard HTML options for the tag. # # ==== Examples @@ -351,16 +358,22 @@ module ActionView # submit_tag "Save edits", :disabled => true # # => # + # # submit_tag "Complete sale", :disable_with => "Please wait..." - # # => # # submit_tag nil, :class => "form_submit" # # => # # submit_tag "Edit", :disable_with => "Editing...", :class => "edit-button" - # # => + # + # submit_tag "Save", :confirm => "Are you sure?" + # # => + # def submit_tag(value = "Save changes", options = {}) options.stringify_keys! -- cgit v1.2.3 From 4cbb9db0a5ff65b0a626a5b043331abefd89e717 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 31 Jan 2010 19:17:42 -0800 Subject: For performance reasons, you can no longer call html_safe! on Strings. Instead, all Strings are always not html_safe?. Instead, you can get a SafeBuffer from a String by calling #html_safe, which will SafeBuffer.new(self). * Additionally, instead of doing concat("".html_safe), you can do safe_concat(""), which will skip both the flag set, and the flag check. * For the first pass, I converted virtually all #html_safe!s to #html_safe, and the tests pass. A further optimization would be to try to use #safe_concat as much as possible, reducing the performance impact if we know up front that a String is safe. --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_view/helpers/form_tag_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 597cf311cb..9b8471c6c6 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -446,7 +446,7 @@ module ActionView concat(tag(:fieldset, options, true)) concat(content_tag(:legend, legend)) unless legend.blank? concat(content) - concat("".html_safe!) + safe_concat("") end private @@ -474,14 +474,14 @@ module ActionView def form_tag_html(html_options) extra_tags = extra_tags_for_form(html_options) - (tag(:form, html_options, true) + extra_tags).html_safe! + (tag(:form, html_options, true) + extra_tags).html_safe end def form_tag_in_block(html_options, &block) content = capture(&block) concat(form_tag_html(html_options)) concat(content) - concat("".html_safe!) + safe_concat("") end def token_tag -- cgit v1.2.3