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

Order

<%=render :partial=>'order_new' %>

Ordered products

Please finalise the order information first...

--------------------------------------------

And…

order_edit.rhtml

Order id: <%[email protected] %>

<%[email protected]_message%>

<%= form_remote_tag :update=>‘order_part’,
:url=> { :id=>@order.id, :action => ‘order_update’}
%>
<%= render :partial=>‘order_form’ %>


<%= 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 %>

Order id: <%[email protected] %>

AH <%[email protected]_lines_message%>

<%=
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 %>

  • <%[email protected]_line.price%>

  • […]
    <% 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.

    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 O. 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.

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs