Commits

Anonymous committed cb83a07

[svn] added support for the on keyword arg in the observe_* functions, and removed
its existing documentation. The arg isn't supported by the current prototype
release, but since there are unofficial patches floating around we'll support
it, just not document it
fixes #142

  • Participants
  • Parent commits c366f19

Comments (0)

Files changed (2)

File tests/test_prototype.py

     def test_observe_field(self):
         self.assertEqual("""<script type="text/javascript">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/reorder_if_empty', {asynchronous:true, evalScripts:true})})\n//]]>\n</script>""",
             observe_field("glass", frequency=300,url='http://www.example.com/reorder_if_empty'))
+        self.assertEqual("""<script type="text/javascript">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/reorder_if_empty', {asynchronous:true, evalScripts:true})}, 'blur')\n//]]>\n</script>""",
+            observe_field("glass", frequency=300,url='http://www.example.com/reorder_if_empty',on="blur"))
 
     def test_observe_form(self):
         self.assertEqual("""<script type="text/javascript">\n//<![CDATA[\nnew Form.Observer('cart', 2, function(element, value) {new Ajax.Request('http://www.example.com/cart_changed', {asynchronous:true, evalScripts:true, parameters:Form.serialize('cart')})})\n//]]>\n</script>""",

File webhelpers/rails/prototype.py

         A JavaScript expression specifying the parameters for the
         XMLHttpRequest. This defaults to 'value', which in the evaluated
         context refers to the new field value.
-    ``on``
-        Specifies which event handler to observe. By default, it's set to
-        "changed" for text fields and areas and "click" for radio buttons
-        and checkboxes. With this, you can specify it instead to be "blur"
-        or "focus" or any other event.
     
     Additionally, you may specify any of the options documented in
     `link_to_remote <#link_to_remote>`_.
     javascript = "new %s('%s', " % (cls, name)
     if options.get('frequency'): 
         javascript += "%s, " % options['frequency']
-    javascript += "function(element, value) {%s})" % callback
+    javascript += "function(element, value) {%s}" % callback
+    if options.get('on'):
+        # FIXME: our prototype isn't supporting the on arg
+        javascript +=", '%s'" % options['on']
+    javascript += ")"
     return javascript_tag(javascript)
 
 def build_callbacks(options):