Rjs template ? (how to check for existence of a dom element?

In my rjs template I’m using the following line.

page.visual_effect :slideUp, ‘comment_error_details’, :duration => 0.5

It works fine if I have created the div with the
id=“comment_error_details”,
but if I haven’t created the error yet then my whole rjs template fails.

How can I check to see if an element has been created? I could then put
the above line in an if statement.

I guess the more broad question would be: Where can I find
documentation on the available methods in rjs templates?

charlie bowman wrote:

In my rjs template I’m using the following line.

page.visual_effect :slideUp, ‘comment_error_details’, :duration => 0.5

It works fine if I have created the div with the
id=“comment_error_details”,
but if I haven’t created the error yet then my whole rjs template fails.

How can I check to see if an element has been created? I could then put
the above line in an if statement.

Hi Charlie,

I am not quite sure if I’ve got your question right. But I would
suggest
just hidding the comment_error_details div and just call page.show
before
before applying the effect…

It turns out that my problem is a little different than I thought. I
decided to create the comment_error div even if there were no errors. I
thought this would solve my problem because the div would always be
there. It turns out that you can’t call the visual effect “slideUp” if
the div is empty. You can call fade on an empty div but you can’t call
slideUp. Is there a way I can check the contents of a div in rjs
templates? I really want to call the slideUp method, but I can only
call it if the div isn’t empty

De Railed wrote:

Hi Charlie,

I am not quite sure if I’ve got your question right. But I would
suggest
just hidding the comment_error_details div and just call page.show
before
before applying the effect…

On Mar 26, 2006, at 9:04 PM, charlie bowman wrote:

In my rjs template I’m using the following line.

page.visual_effect :slideUp, ‘comment_error_details’, :duration
=> 0.5

It works fine if I have created the div with the
id=“comment_error_details”,
but if I haven’t created the error yet then my whole rjs template
fails.

page << “if($(‘my_div’)) {”
page.replace_html my_div, :partial => ?foo?
page << “}”

from <http://rails.techno-weenie.net/question/2006/3/24/
rjs_templates_checking_if_element_exists>


Jason P.
[email protected]

“The key to performance is elegance, not
battalions of special cases.”

  • Jon Bentley and Doug McIlroy

On Mar 26, 2006, at 9:09 PM, charlie bowman wrote:

I guess the more broad question would be: Where can I find
documentation on the available methods in rjs templates?

Documentation for RJS is still hard to come by. http://rails.techno-
weenie.net has some good stuff as well as:

http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates
<http://www.codyfauser.com/articles/2006/03/16/rjs-element-and-
collection-proxies>

As well as the Edge Rails Documentation itself:

<http://edgedocs.planetargon.org/classes/ActionView/Helpers/
ScriptaculousHelper.html>
<http://edgedocs.planetargon.org/classes/ActionView/Helpers/
PrototypeHelper/JavaScriptGenerator.html>
<http://edgedocs.planetargon.org/classes/ActionView/Helpers/
PrototypeHelper.html>
<http://edgedocs.planetargon.org/classes/ActionView/Helpers/
PrototypeHelper.html>


Jason P.
[email protected]

“The key to performance is elegance, not
battalions of special cases.”

  • Jon Bentley and Doug McIlroy

I’ve checked those sites, but it seems that there just isn’t any info
out there yet.

Jason P. wrote:

On Mar 26, 2006, at 9:09 PM, charlie bowman wrote:

I guess the more broad question would be: Where can I find
documentation on the available methods in rjs templates?

Documentation for RJS is still hard to come by. http://rails.techno-
weenie.net has some good stuff as well as:

http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates
<http://www.codyfauser.com/articles/2006/03/16/rjs-element-and-
collection-proxies>

I’ve checked those sites, but it seems that there just isn’t any info
out there yet.

cd to your rails directory (the framework, not your app), delete doc/
and run ‘rdoc’ - a few minutes later you will have docs. pretty much
everything is documented. you can peruse the ruby and resultant HTML
sources to get a better understanding…