aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-13 16:35:15 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-13 16:35:15 +0000
commit1e24600e724fc1971d85a1734528b14444f58895 (patch)
tree600171c7dbc24837b41cc10f6bd68b79c2cfd3a1 /actionpack/lib/action_view
parent7816420c63f8e03b497b420d190a38db7ed44b0c (diff)
downloadrails-1e24600e724fc1971d85a1734528b14444f58895.tar.gz
rails-1e24600e724fc1971d85a1734528b14444f58895.tar.bz2
rails-1e24600e724fc1971d85a1734528b14444f58895.zip
Added Field.present, .focus, and .clear as JS convenience for working with forms. Removed link_to_display_toggle in favor of link_to_function "Cancel", "toggle_display("add_item_link", "add_item_form")"
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@895 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/javascript_helper.rb27
1 files changed, 26 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index 83538490ee..05dd8b6bb3 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -55,6 +55,24 @@ module ActionView
def define_javascript_functions
<<-EOF
<script language="JavaScript">
+ /* Convenience form methods */
+ Field = {
+ clear: function() {
+ for(i = 0; i < arguments.length; i++) { o(arguments[i]).value = ''; }
+ return true;
+ },
+
+ focus: function(id) {
+ o(id).focus();
+ return true;
+ },
+
+ present: function() {
+ for(i = 0; i < arguments.length; i++) { if (o(arguments[i]).value = '') { return false; } }
+ return true;
+ }
+ }
+
/* XMLHttpRequest Methods */
function update_with_response() {
@@ -104,6 +122,12 @@ module ActionView
o(id).style.display = (o(id).style.display == "none") ? "" : "none";
}
+ function toggle_display() {
+ for(i = 0; i < arguments.length; i++) {
+ o(arguments[i]).style.display = (o(arguments[i]).style.display == "none") ? "" : "none";
+ }
+ }
+
function o(id) {
return document.getElementById(id);
}
@@ -178,7 +202,8 @@ module ActionView
"update_with_response('#{options[:update]}', '#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})" :
"xml_request('#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})"
- function = [ options[:before], function, options[:before] ].join("; ")
+ function = "#{options[:before]}; #{function}" if options[:before]
+ function = "#{function}; #{options[:after]}" if options[:after]
function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
return function