Page.insert_html using element select instead of id?

I'm trying to do something like in a rjs file:

page.insert_html :bottom, page.literal(" $('comments_list').down(0) "), :partial => "comments/comment_list", :object => @comment

The problem is that I always get this error: "RJS error: TypeError: null has no properties"

Sometimes I can't understand rjs.

Any ideas?

Don't think that's going to work... check out the source for the insert_html method. It has the following line:

record "Element.insert(\"#{id}\", { #{position.to_s.downcase}: #{content} });"

So your page.literal isn't going to do any good as the method is wrapping it in double quotes...

Doesn't seem like it would be hard to modify to do what you want though...

-philip

Thanks for the quick answer, but nothing yet.

Philip Hallstrom wrote:

record "Element.insert(\"#{id}\", { #{position.to_s.downcase}: #{content} });"

This is the helper source code, but if you go to the Prototype API you will see:

insert(element, { position: content }) -> HTMLElement

So, I understand that you can pass a element. I just can't get the helper to evaluate the JS code that lead me to the element.

Thanks for the quick answer, but nothing yet.

Philip Hallstrom wrote: > record "Element.insert(\"#{id}\", { #{position.to_s.downcase}: > #{content} });"

This is the helper source code, but if you go to the Prototype API you will see:

> insert(element, { position: content }) -> HTMLElement

So, I understand that you can pass a element. I just can't get the

helper to evaluate the JS code that lead me to the element.

if rjs is getting in the way (sounds like it is) there's nothing wrong with just ditching the helpers

fred

Hi,

I gave an ID to the UL element and solved my problem. But I'm not happy with that... still looking for a more dynamic way to do it.

Some people could do it using:

page.insert_html :bottom, page.literal("$$('p.welcome b').first()"), "Some item"

and it is not working for me sadly.

thanks,

David Sousa

Easy to solve your unhappyness because other people use the "$$" function while you just use the "$" function from prototype. $$ ('#comments_list ul') is waht you need to add, obviously.

chosen wrote:

Easy to solve your unhappyness because other people use the "$$" function while you just use the "$" function from prototype. $$ ('#comments_list ul') is waht you need to add, obviously.

Hi chosen, thanks for your attention but did not work as well.

I tried:

page.insert_html :bottom, page.literal("$$('#comments_list ul')"), :partial => "comments/comment_list", :object => @comment

but with no success.

Thanks anyway.

David Sousa

chosen wrote: > Easy to solve your unhappyness because other people use the "$$" > function while you just use the "$" function from prototype. $$ > ('#comments_list ul') is waht you need to add, obviously.

Have you tried using page.select ? it yields those elements matching the selector you pass it.

Fred

> Element.insert("#<ActionView::Helpers::JavaScriptVariableProxy:0x7f97a1c5eb 18>"...

So the JS can't find the element.

I thank you for your help. But I think I will just put an id to the ul element and solve the problem. RJS and prototype is difficult and poorly documented, I can't understand the true advantage behind rjs and pro.

Prototype is fine, but RJS can only do so much. Nothing wrong with ditching RJS if you need more than it can give.

Fred

On Aug 11, 5:23 pm, David Sousa <rails-mailing-l...@andreas-s.net> wrote:> > Element.insert("#<ActionView::Helpers::JavaScriptVariableProxy:0x7f97a1c5eb 18>"...

> So the JS can't find the element.

> I thank you for your help. But I think I will just put an id to the ul > element and solve the problem. RJS and prototype is difficult and poorly > documented, I can't understand the true advantage behind rjs and pro.

Prototype is fine, but RJS can only do so much. Nothing wrong with ditching RJS if you need more than it can give.

oh, and page.literal("$$('#comments_list ul')") may not have worked because $$('#comments_list ul') returns an array whereas insert is probably expecting a single element. $$('#comments_list ul')[0] might work better.

Fred

Fred, I think that page.literal is not working for me. Every thing that I do generates a JS code like:

try { Element.insert("$$( '#comments_list ul').first ", ...

But, if the $$( '#comments_list ul').first code is inside "", the code will never be evaluated and the insert function will always look for a element with and id like: $$( '#comments_list ul').first

This might be the big problem... I don't know.

David Sousa