aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_tag_helper.rb
diff options
context:
space:
mode:
authorErik St. Martin <alakriti@gmail.com>2010-01-24 11:57:38 -0500
committerStefan Penner <stefan.penner@gmail.com>2010-01-27 12:44:33 -0600
commit463fc7110755485ee2644690cb87023357f92f9a (patch)
tree6c014a65a8265795cd1c4723f6d1c8cc66f72acf /actionpack/lib/action_view/helpers/form_tag_helper.rb
parentc3baf8b767bdfb27b90b2120f9512d9697e5e932 (diff)
downloadrails-463fc7110755485ee2644690cb87023357f92f9a.tar.gz
rails-463fc7110755485ee2644690cb87023357f92f9a.tar.bz2
rails-463fc7110755485ee2644690cb87023357f92f9a.zip
making non remote versions of link_to, button_to, submit_tag and image_submit_tag output data attributes for things like :confirm, :method, :popup, and :disable_with
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_tag_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb20
1 files changed, 5 insertions, 15 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 048bedc7ba..ebce5c1513 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -352,33 +352,24 @@ module ActionView
# # => <input disabled="disabled" name="commit" type="submit" value="Save edits" />
#
# submit_tag "Complete sale", :disable_with => "Please wait..."
- # # => <input name="commit" onclick="this.disabled=true;this.value='Please wait...';this.form.submit();"
+ # # => <input name="commit" data-disable-with="Please wait..."
# # type="submit" value="Complete sale" />
#
# submit_tag nil, :class => "form_submit"
# # => <input class="form_submit" name="commit" type="submit" />
#
# submit_tag "Edit", :disable_with => "Editing...", :class => "edit-button"
- # # => <input class="edit-button" onclick="this.disabled=true;this.value='Editing...';this.form.submit();"
+ # # => <input class="edit-button" data-disable-with="Editing..."
# # name="commit" type="submit" value="Edit" />
def submit_tag(value = "Save changes", options = {})
options.stringify_keys!
if disable_with = options.delete("disable_with")
- disable_with = "this.value='#{disable_with}'"
- disable_with << ";#{options.delete('onclick')}" if options['onclick']
-
- options["onclick"] = "if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }"
- options["onclick"] << "else { hiddenCommit = document.createElement('input');hiddenCommit.type = 'hidden';"
- options["onclick"] << "hiddenCommit.value = this.value;hiddenCommit.name = this.name;this.form.appendChild(hiddenCommit); }"
- options["onclick"] << "this.setAttribute('originalValue', this.value);this.disabled = true;#{disable_with};"
- options["onclick"] << "result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());"
- options["onclick"] << "if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;"
+ add_disable_with_to_attributes!(options, disable_with)
end
if confirm = options.delete("confirm")
- options["onclick"] ||= 'return true;'
- options["onclick"] = "if (!#{confirm_javascript_function(confirm)}) return false; #{options['onclick']}"
+ add_confirm_to_attributes!(options, confirm)
end
tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys)
@@ -411,8 +402,7 @@ module ActionView
options.stringify_keys!
if confirm = options.delete("confirm")
- options["onclick"] ||= ''
- options["onclick"] += "return #{confirm_javascript_function(confirm)};"
+ add_confirm_to_attributes!(options, confirm)
end
tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options.stringify_keys)