How can I know if a an element is visible or hidden in RJS
I’m trying to hide/show some data but it does not work
Error => parse error, unexpected $undefined.
#show_doctor.rjs
if($("#{@element}").visible())
page.hide “hide_#{@element}”
end
Any ideas?
@element contains the value of the html element
This code should work if @element contains the id of the html element,
what do you have exactly in @element ?
Btw since hiding an already hidden element won’t do anything you don’t
even need to test if it is visible ^^
You can then rewrite it like this:
page[“hide_#{@element}”].hide()
Yes, there is a page[‘element’].toggle function but the problem is that
I need to check if an object is displayed, if not I want to display it
and at the same time do more stuff… (ie hide or show more elements)
I had to do a quick hack, perhaps it is not the best way to do it but
for the time been I will do the following
I’m sending the id with the hide_ or show_ prefix and then check
if @element.starts_with?(“show_”)
page.show “whatever”
more stuff
else
page.hide “whatever”
something else
end
If it works, that’s great.
The problem with RJS in this case is that the RJS template needs to be
rendered in one shot before sending it to the browser. There is no way
to query JS objects on the other side and have that alter the rendering.
I see two ways to deal with this.
One would be to use the RJS template to generate a JS script that could
do the conditional processing on the client browser, and the other way
would be to pack all the information you need into a proxy object that
gets sent along with the request (sort of like how you have already done
it).