Forum: Ruby on Rails Help with an RJS

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.
A1247f73598357f06388e863c41aa624?d=identicon&s=25 Elias Orozco (elioncho)
on 2008-10-30 22:56
(Received via mailing list)
Hello, I have a code on a RJS where I want to check if an element in
the DOM has child elements, if not, show a message.

1.page["event_"+@event.id.to_s].visual_effect :fade #This works
2.page << "if $('single_blog_info_box_480').childElements().length ==
0 {"
3.page["message"].visual_effect :appear
4.page << "}"

Line 1 is working. It removes an event from the view. The problem is
in line 2. I am calling childElements on a div called
'single_blog_info_box_480' (which contains the events). The idea is to
make a message appear when there are no more events left. The thing is
that I currently have 3 events and everytime the RJS is executed it
shows the same 3 events even though events have become hidden. Can
somebody guide me on how to do this or what the problem is?

Thanks,

Elioncho
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-30 23:06
(Received via mailing list)
On 30 Oct 2008, at 21:55, elioncho wrote:

> Line 1 is working. It removes an event from the view. The problem is
> in line 2. I am calling childElements on a div called
> 'single_blog_info_box_480' (which contains the events). The idea is to
> make a message appear when there are no more events left. The thing is
> that I currently have 3 events and everytime the RJS is executed it
> shows the same 3 events even though events have become hidden. Can
> somebody guide me on how to do this or what the problem is?
>
you need to have () surrounding the condition.

Fred
A1247f73598357f06388e863c41aa624?d=identicon&s=25 Elias Orozco (elioncho)
on 2008-10-30 23:41
(Received via mailing list)
I added the () but that's not the problem. I added the next alert and
it shows the events length. But if I remove another event it still
shows the same number.

page << "alert($('single_blog_info_box_480').childElements().length)"




On Oct 30, 5:05 pm, Frederick Cheung <frederick.che...@gmail.com>
D22781eccd92073acd6a1ed350c3d136?d=identicon&s=25 boblu (Guest)
on 2008-10-31 01:03
(Received via mailing list)
why don't you write 2--4 line into a single line ?

page << "if ($('single_blog_info_box_480').childElements().length ==
0 ){$('message').Appear;}"
A1247f73598357f06388e863c41aa624?d=identicon&s=25 Elias Orozco (elioncho)
on 2008-10-31 03:00
(Received via mailing list)
The childElements length never changes when I make the event
disappear. It's like it remains with what initially is loaded on the
html eventhough I have hide this elements.
9b4c04c050122bcea16a6f3376d680fa?d=identicon&s=25 Daniel Bush (danb)
on 2008-10-31 03:45
(Received via mailing list)
elioncho wrote:

> The childElements length never changes when I make the event
> disappear. It's like it remains with what initially is loaded on the
> html eventhough I have hide this elements.
>

I don't use these effects a lot, but the fade effect in prototype/
scriptaculous is probably setting the css 'display' property to none
to take it out of the visual display of the document.  It's still
sitting there in the dom, so 'childElements' is probably counting it;
it's just that it doesn't appear in the visual flow.


--
Daniel Bush
A1247f73598357f06388e863c41aa624?d=identicon&s=25 Elias Orozco (elioncho)
on 2008-10-31 04:10
(Received via mailing list)
Thanks all of you for help. Daniel I think that's what's happening.
I'll try another approach.

Elioncho
This topic is locked and can not be replied to.