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

Changeset 6930

Show
Ignore:
Timestamp:
06/03/07 14:27:43 (3 years ago)
Author:
madrobby
Message:

Allow JSON-style values for the :with option of observe_field. Closes #8557 [kommen]

Files:

Legend:

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

    r6923 r6930  
    11*SVN* 
     2 
     3* Allow JSON-style values for the :with option of observe_field.  Closes #8557 [kommen] 
    24 
    35* Remove RAILS_ROOT from backtrace paths.  #8540 [Tim Pope] 
  • trunk/actionpack/lib/action_view/helpers/prototype_helper.rb

    r6775 r6930  
    699699     
    700700      def build_observer(klass, name, options = {}) 
    701         if options[:with] && (options[:with] !~ /[=(.]/) 
     701        if options[:with] && (options[:with] !~ /[\{=(.]/) 
    702702          options[:with] = "'#{options[:with]}=' + value" 
    703703        else 
  • trunk/actionpack/test/template/prototype_helper_test.rb

    r6894 r6930  
    175175  end 
    176176   
     177  def test_observe_field_using_with_option 
     178    expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:'id=' + value})})\n//]]>\n</script>) 
     179    assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => 'id') 
     180    assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + value") 
     181  end 
     182   
     183  def test_observe_field_using_json_in_with_option 
     184    expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:{'id':value}})})\n//]]>\n</script>) 
     185    assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "{'id':value}")     
     186  end 
     187   
    177188  def test_observe_field_using_function_for_callback 
    178189    assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {alert('Element changed')})\n//]]>\n</script>),