Skip to content

Commit

Permalink
Changed the observe field node into a div with display:none
Browse files Browse the repository at this point in the history
  • Loading branch information
foobarfighter authored and stefanpenner committed Jan 27, 2010
1 parent fab8b25 commit 88e793e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
11 changes: 8 additions & 3 deletions actionpack/lib/action_view/helpers/ajax_helper.rb
Expand Up @@ -38,12 +38,17 @@ def observe_field(name, options = {}, html_options = {})
url = options.delete(:url) url = options.delete(:url)
url = url_for(url) if url.is_a?(Hash) 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 html_options[:"data-frequency"] = frequency
end end


html_options.merge!(:"data-observe" => true, :"data-url" => url) html_options.merge!(:style => "display:none",
tag(:input, html_options) :"data-observe-field" => name,
:"data-observe" => true,
:"data-url" => url)

tag(:div, html_options)
end end


module Rails2Compatibility module Rails2Compatibility
Expand Down
20 changes: 12 additions & 8 deletions actionpack/test/javascript/ajax_test.rb
Expand Up @@ -123,22 +123,26 @@ def field(options = {})


test "basic" do test "basic" do
assert_html field, assert_html field,
%w(data-observe="true") %w(div style="display:none" data-observe="true" data-observe-field="title")
end

test "with a :frequency option" do
assert_html field(:frequency => 5.minutes),
%w(data-observe="true" data-frequency="300")
end end


test "using a url string" do test "using a url string" do
assert_html field(:url => "/some/other/url"), assert_html field(:url => "/some/other/url"),
%w(data-observe="true" data-url="/some/other/url") %w(data-url="/some/other/url")
end end


test "using a url hash" do test "using a url hash" do
assert_html field(:url => {:controller => :blog, :action => :update}), 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 end


# def test_observe_field # def test_observe_field
Expand Down

0 comments on commit 88e793e

Please sign in to comment.