Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3926

Show
Ignore:
Timestamp:
03/18/06 16:08:09 (3 years ago)
Author:
david
Message:

Added :function option to PrototypeHelper#observe_field/observe_form that allows you to call a function instead of submitting an ajax call as the trigger (closes #4268) [jonathan@daikini.com]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r3917 r3926  
    11*SVN* 
     2 
     3* Added :function option to PrototypeHelper#observe_field/observe_form that allows you to call a function instead of submitting an ajax call as the trigger #4268 [jonathan@daikini.com] 
    24 
    35* Make Mime::Type.parse consider q values (if any) [Jamis Buck] 
  • trunk/actionpack/lib/action_view/helpers/prototype_helper.rb

    r3858 r3926  
    316316      # an Ajax call when its contents have changed. 
    317317      #  
    318       # Required +options+ are
     318      # Required +options+ are either of
    319319      # <tt>:url</tt>::       +url_for+-style options for the action to call 
    320320      #                       when the field has changed. 
     321      # <tt>:function</tt>::  Instead of making a remote call to a URL, you 
     322      #                       can specify a function to be called instead. 
    321323      #  
    322324      # Additional options are: 
     
    703705        end 
    704706 
    705         callback = remote_function(options) 
     707        callback = options[:function] || remote_function(options) 
    706708        javascript  = "new #{klass}('#{name}', " 
    707709        javascript << "#{options[:frequency]}, " if options[:frequency] 
  • trunk/actionpack/test/template/prototype_helper_test.rb

    r3856 r3926  
    109109  end 
    110110   
     111  def test_observe_field_using_function_for_callback 
     112    assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {alert('Element changed')})\n//]]>\n</script>), 
     113      observe_field("glass", :frequency => 5.minutes, :function => "alert('Element changed')") 
     114  end 
     115   
    111116  def test_observe_form 
    112117    assert_dom_equal %(<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})})\n//]]>\n</script>), 
    113118      observe_form("cart", :frequency => 2, :url => { :action => "cart_changed" }) 
     119  end 
     120   
     121  def test_observe_form_using_function_for_callback 
     122    assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('cart', 2, function(element, value) {alert('Form changed')})\n//]]>\n</script>), 
     123      observe_form("cart", :frequency => 2, :function => "alert('Form changed')") 
    114124  end 
    115125