Permalink
Browse files

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
  • Loading branch information...
1 parent 7816420 commit 1e24600e724fc1971d85a1734528b14444f58895 @dhh dhh committed Mar 13, 2005
Showing with 26 additions and 1 deletion.
  1. +26 −1 actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -55,6 +55,24 @@ def form_remote_tag(options = {})
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 @@ def define_javascript_functions
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 @@ def remote_function(options)
"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

0 comments on commit 1e24600

Please sign in to comment.