Tony Mobily
2006-Jul-24 17:40 UTC
[Rails] BIG JS limit? Using replace_html with partials containing JS
Hello, It''s pretty hard giving a practical example on this one. I have a partial which contains some generated Javascript. Something like: order_screen.rhtml ------------------------------------------- <h1>Order</h1> <div id="order_part"> <%=render :partial=>''order_new'' %> </div> <h1>Ordered products</h1> <div id="order_lines_part"> <p>Please finalise the order information first...</p> </div> -------------------------------------------- And... order_edit.rhtml ------------------------------------------- <h2>Order id: <%=@order.id %></h2> <div id="order_message"><%=@order_message%></div> <%= form_remote_tag :update=>''order_part'', :url=> { :id=>@order.id, :action => ''order_update''} %> <%= render :partial=>''order_form'' %> </p> <%= submit_tag ''Modify'' %> <%= end_form_tag %> <%update_page_tag do |page| page.delay(2) do page.visual_effect :fade, ''order_message'' end end %> <%=update_page_tag do |page| page.replace_html ''order_lines_part'', :partial=>''order_lines_index'', :locals=>{ :fade_message => false} end ------------------------------------------------------ I am having tons and tons of problems, because order_line_index.rhtml contains: order_line_index.rhtml ------------------------------------------------------ <% no_message ||= false %> <h2>Order id: <%=@order.id %></h2> <div id="order_lines_message"> AH <%=@order_lines_message%></div> <% update_page_tag do |page| page.delay(3) do page.visual_effect :fade, ''order_lines_message'' end end end %> <% render :partial=>''order_lines_form'' %> <% for @order_line in @order.order_lines %> <li><%=@order_line.price%></li> [...] <% end %> --------------------------------------------------------- Basically, things don''t work because anything rendered using page.replace_html doesn''t seem to be able to contain any javascript, because the javascript code will be spit out on the page. Do you know of any limits with page.replace_html? Can I only render partials which are STRICTLY html? If so, the limitation seems to be huge! If you have any info, please let me know. I have lost it over this one... Bye, Merc. -- Posted via http://www.ruby-forum.com/.
Rick Olson
2006-Jul-24 18:07 UTC
[Rails] BIG JS limit? Using replace_html with partials containing JS
> Basically, things don''t work because anything rendered using > page.replace_html doesn''t seem to be able to contain any javascript, > because the javascript code will be spit out on the page. > > Do you know of any limits with page.replace_html? Can I only render > partials which are STRICTLY html? If so, the limitation seems to be > huge! > > If you have any info, please let me know. I have lost it over this > one... > > Bye, > > Merc. >I''d say it''s a limit of the browsers and their DOM Implementations. You may have to be creative here. For instance replace the html and then run fades, etc afterwards. Use something like Event Selectors to attach javascript events for any remote links/forms you may be inserting. -- Rick Olson http://techno-weenie.net
Tony Mobily
2006-Jul-24 18:16 UTC
[Rails] Re: BIG JS limit? Using replace_html with partials containin
Rick Olson wrote:> I''d say it''s a limit of the browsers and their DOM Implementations. > You may have to be creative here. For instance replace the html and > then run fades, etc afterwards. Use something like Event Selectors to > attach javascript events for any remote links/forms you may be > inserting.Ouch. Can anybody else here confirm that you can''t have Javascript code in a partial that is rendered by replace_html...? This is important because my partials use Javascript of all sorts of things - auto-completion, lookup, etc. This would really suck... It''s not only pretty effects I am after! Bye, Merc. -- Posted via http://www.ruby-forum.com/.