Forum: Ruby on Rails rjs template ? (how to check for existence of a dom element?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 Charlie Bowman (beachguy82)
on 2006-03-27 05:04
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.
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 Charlie Bowman (beachguy82)
on 2006-03-27 05:09
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.
83ed21e86ee86270ad79111048ea819c?d=identicon&s=25 De Railed (derailed)
on 2006-03-27 05:20
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...
2899cec9af525f7953e19c8210aca97c?d=identicon&s=25 Jason Perkins (Guest)
on 2006-03-27 05:37
(Received via mailing list)
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 Perkins
jperkins@sneer.org

"The key to performance is elegance, not
  battalions of special cases."
  - Jon Bentley and Doug McIlroy
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 Charlie Bowman (beachguy82)
on 2006-03-27 05:40
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...
2899cec9af525f7953e19c8210aca97c?d=identicon&s=25 Jason Perkins (Guest)
on 2006-03-27 05:47
(Received via mailing list)
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/rail...
<http://www.codyfauser.com/articles/2006/03/16/rjs-...
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 Perkins
jperkins@sneer.org

"The key to performance is elegance, not
  battalions of special cases."
  - Jon Bentley and Doug McIlroy
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 Charlie Bowman (beachguy82)
on 2006-03-27 06:10
I've checked those sites, but it seems that there just isn't any info
out there yet.

Jason Perkins 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/rail...
> <http://www.codyfauser.com/articles/2006/03/16/rjs-...
> collection-proxies>
>
E54a059675e8e64474988e2faffdcb3b?d=identicon&s=25 ix (Guest)
on 2006-03-27 06:51
> 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..
This topic is locked and can not be replied to.