diff options
-rw-r--r-- | actionpack/lib/action_view/helpers/ajax_helper.rb | 11 | ||||
-rw-r--r-- | actionpack/test/javascript/ajax_test.rb | 20 |
2 files changed, 20 insertions, 11 deletions
diff --git a/actionpack/lib/action_view/helpers/ajax_helper.rb b/actionpack/lib/action_view/helpers/ajax_helper.rb index 02245d9a1e..fce756869c 100644 --- a/actionpack/lib/action_view/helpers/ajax_helper.rb +++ b/actionpack/lib/action_view/helpers/ajax_helper.rb @@ -84,12 +84,17 @@ module ActionView url = options.delete(:url) url = url_for(url) if url.is_a?(Hash) - if frequency = options.delete(:frequency) + frequency = options.delete(:frequency) + if frequency && frequency > 0 html_options[:"data-frequency"] = frequency end - html_options.merge!(:"data-observe" => true, :"data-url" => url) - tag(:input, html_options) + html_options.merge!(:style => "display:none", + :"data-observe-field" => name, + :"data-observe" => true, + :"data-url" => url) + + tag(:div, html_options) end module Rails2Compatibility diff --git a/actionpack/test/javascript/ajax_test.rb b/actionpack/test/javascript/ajax_test.rb index 6539583398..e46e346d79 100644 --- a/actionpack/test/javascript/ajax_test.rb +++ b/actionpack/test/javascript/ajax_test.rb @@ -123,22 +123,26 @@ class ObserveFieldTest < AjaxTestCase test "basic" do assert_html field, - %w(data-observe="true") - end - - test "with a :frequency option" do - assert_html field(:frequency => 5.minutes), - %w(data-observe="true" data-frequency="300") + %w(div style="display:none" data-observe="true" data-observe-field="title") end test "using a url string" do assert_html field(:url => "/some/other/url"), - %w(data-observe="true" data-url="/some/other/url") + %w(data-url="/some/other/url") end test "using a url hash" do assert_html field(:url => {:controller => :blog, :action => :update}), - %w(data-observe="true" data-url="/url/hash") + %w(data-url="/url/hash") + end + + test "with a :frequency option" do + assert_html field(:frequency => 5.minutes), + %w(data-frequency="300") + end + + test "with a :frequency option of 0" do + assert_no_match /data-frequency/, field(:frequency => 0) end # def test_observe_field |